from typing import Union

from mongoengine.fields import ObjectId
from pydantic import BaseModel, validator


class InDBBase(BaseModel):
    id: str = None

    @validator("id", pre=True)
    def _objectid_to_str(cls, value: Union[ObjectId, str]) -> str:
        if isinstance(value, ObjectId):  # here value is ObjectId
            return str(value)
        return value

    class Config:
        orm_mode = True

8c2e1b673b4278e9bed5a9da1aad234081caa8b4
<mask token>

<mask token>


class InDBBase(BaseModel):
    id: str = None
    <mask token>


    class Config:
        orm_mode = True

<mask token>


class InDBBase(BaseModel):
    id: str = None

    @validator('id', pre=True)
    def _objectid_to_str(cls, value: Union[ObjectId, str]) ->str:
        if isinstance(value, ObjectId):
            return str(value)
        return value


    class Config:
        orm_mode = True

from typing import Union
from mongoengine.fields import ObjectId
from pydantic import BaseModel, validator


class InDBBase(BaseModel):
    id: str = None

    @validator('id', pre=True)
    def _objectid_to_str(cls, value: Union[ObjectId, str]) ->str:
        if isinstance(value, ObjectId):
            return str(value)
        return value


    class Config:
        orm_mode = True

from typing import Union

from mongoengine.fields import ObjectId
from pydantic import BaseModel, validator


class InDBBase(BaseModel):
    id: str = None

    @validator("id", pre=True)
    def _objectid_to_str(cls, value: Union[ObjectId, str]) -> str:
        if isinstance(value, ObjectId):  # here value is ObjectId
            return str(value)
        return value

    class Config:
        orm_mode = True
