Skip to content
Discussion options

You must be logged in to vote

Yes it is reasonable to modify the dictionaries that result from model_dumping a pydantic model. There are actually quite a few data types that pydantic doesn't know how to serialize, and simply skips (this is an irrelevant detail for your case, but this is because those data types don't define a __get_pydantic_core_schema__ classmethod). Enums are a good example, there are also quite a few pymatgen classes as well that won't serialize correctly when calling model_dump.

Emmet has a utility function that can help with this though:

def jsanitize(obj, strict=False, allow_bson=False):

Rather than mess with manually ser…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@LuckRookie
Comment options

@tsmathis
Comment options

Answer selected by LuckRookie
@LuckRookie
Comment options

@tsmathis
Comment options

@LuckRookie
Comment options

@tsmathis
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants