Skip to content

Commit

Permalink
api.models: remove user model serializers
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jeny Sadadia authored and nuclearcat committed Nov 26, 2024
1 parent 25b3dc4 commit e82bcfe
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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"""
Expand Down

0 comments on commit e82bcfe

Please sign in to comment.