Skip to content

Conversation

@jefersondaniel
Copy link
Owner

@jefersondaniel jefersondaniel commented Jul 6, 2024

I'm sending this PR as a draft because the tests don't pass yet. The JSON mode of pydantic also affects the datetime serialization so it creates a break compatibility.

"""
model_with_id = cast(ModelWithId, model)
data = model_with_id.model_dump()
data = model_with_id.model_dump(mode="json")
Copy link
Contributor

@KozyrevIvan KozyrevIvan Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should exclude computed_field here

This can be done for example like this:

computed_fields = set(model.model_computed_fields)
data = model_with_id.model_dump(
    mode="json", 
    exclude=computed_fields,
 )

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue I see is storing a Date object in mongo and also supporting a Enum. Converting it to JSON would convert the Date type into a "string" because JSON don't have Date times, its part of BSON.

@jefersondaniel jefersondaniel mentioned this pull request Mar 19, 2025
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.

2 participants