Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added in a new object id field for mongodb #151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SkandaPrasad-S
Copy link

@SkandaPrasad-S SkandaPrasad-S commented Mar 3, 2024

Hi everyone -> this is for issue #133

I have been able to add a new pydantic object id field but I am facing some issues with serialisation and testing it

The field is validated correctly when used like

class Something(BaseModel):
    object_id: ObjectIdField

But I am facing some problem in doing Something.model_json_schema(mode="serialization").

Can someone look through my code and help me see what is wrong or what I need to change?

@Ale-Cas
Copy link

Ale-Cas commented Mar 4, 2024

Hi everyone -> this is for issue #133

I have been able to add a new pydantic object id field but I am facing some issues with serialisation and testing it

The field is validated correctly when used like

class Something(BaseModel):
    object_id: ObjectIdField

But I am facing some problem in doing Something.model_json_schema(mode="serialization").

Can someone look through my code and help me see what is wrong or what I need to change?

I think to solve this you might need to implement this method:

@classmethod
def __get_pydantic_json_schema__(
        cls, schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler
    ) -> dict[str, Any]: ...

similar to how it is implemented for other types

pydantic_extra_types/mongo_objectId.py Outdated Show resolved Hide resolved
pydantic_extra_types/mongo_objectId.py Show resolved Hide resolved
requirements/pyproject.txt Show resolved Hide resolved
SkandaPrasad-S and others added 2 commits March 5, 2024 10:17
Co-authored-by: Yasser Tahiri <yasserth19@gmail.com>
Co-authored-by: Alessio Castrica <64859146+Ale-Cas@users.noreply.github.com>
@Ale-Cas
Copy link

Ale-Cas commented Mar 6, 2024

Also can you rename the new files to snake case (mongo_object_id.py and test_mongo_object_id.py) to follow the convention of other file names?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants