From e82bcfe537d0ffa3da91e57724d2495f0d3643f8 Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Mon, 18 Nov 2024 15:13:37 +0530 Subject: [PATCH] api.models: remove user model serializers Remove model serializers of `User` and `UserRead` classes as model serializer of parent class `DatabaseModel` handles its serialization in `json` mode. Signed-off-by: Jeny Sadadia --- api/models.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/api/models.py b/api/models.py index c3fb85a3..07c57eb2 100644 --- a/api/models.py +++ b/api/models.py @@ -12,11 +12,10 @@ """Server-side model definitions""" from datetime import datetime -from typing import Optional, TypeVar, Dict, Any, List +from typing import Optional, TypeVar, List from pydantic import ( BaseModel, Field, - model_serializer, field_validator, ) from typing_extensions import Annotated @@ -107,15 +106,6 @@ def get_indexes(cls): cls.Index('email', {'unique': True}), ] - @model_serializer(when_used='json') - def serialize_model(self) -> Dict[str, Any]: - """Serialize model by converting PyObjectId to string""" - values = self.__dict__.copy() - for field_name, value in values.items(): - if isinstance(value, PydanticObjectId): - values[field_name] = str(value) - return values - class UserRead(schemas.BaseUser[PydanticObjectId], ModelId): """Schema for reading a user""" @@ -130,15 +120,6 @@ def validate_groups(cls, groups): # pylint: disable=no-self-argument raise ValueError("Groups must have unique names.") return groups - @model_serializer(when_used='json') - def serialize_model(self) -> Dict[str, Any]: - """Serialize model by converting PyObjectId to string""" - values = self.__dict__.copy() - for field_name, value in values.items(): - if isinstance(value, PydanticObjectId): - values[field_name] = str(value) - return values - class UserCreate(schemas.BaseUserCreate): """Schema for creating a user"""