You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We ran into some issues with serialization when migrating (subclass data loss). It wasn't until finding this bug that led us to discover the docs with the Migration warning stating you need to use SerializeAsAny.
This is less a bug and more a request to put this front and center in the migration doc. We lost a lot of time trying to figure this out and given that serialization is so essential for any API, esp FastAPI, this isn't something that should require a ton of searching to figure out.
Anyway, wondering if there is a possible plan to implement this logic within the model_config = ConfigDict()? I think it would make more intuitive sense.
From Docs, perhaps add to migration guide: This behavior is different from how things worked in Pydantic V1, where we would always include all (subclass) fields when recursively dumping models to dicts. The motivation behind this change in behavior is that it helps ensure that you know precisely which fields could be included when serializing, even if subclasses get passed when instantiating the object. In particular, this can help prevent surprises when adding sensitive information like secrets as fields of subclasses.
Anyway, wondering if there is a possible plan to implement this logic within the model_config = ConfigDict()? I think it would make more intuitive sense.
We decided it would be better as a runtime flag, see pydantic/pydantic-core#740. The constraint has been bandwidth in implementation. A contribution to move that work forward or to improve the docs would be very welcome!
FWIW I'd like this to be configurable rather than a runtime flag. I'd like to be able to take advantage of the new default behaviour where it makes sense, but I'd also like to not have to shotgun SerializeAsAny throughout my codebases as well.
Libraries that embed Pydantic (e.g. FastAPI) may not expose this via it's API, which would be another reason to avoid the runtime arg.
Initial Checks
Description
We ran into some issues with serialization when migrating (subclass data loss). It wasn't until finding this bug that led us to discover the docs with the Migration warning stating you need to use SerializeAsAny.
This is less a bug and more a request to put this front and center in the migration doc. We lost a lot of time trying to figure this out and given that serialization is so essential for any API, esp FastAPI, this isn't something that should require a ton of searching to figure out.
Anyway, wondering if there is a possible plan to implement this logic within the
model_config = ConfigDict()
? I think it would make more intuitive sense.From Docs, perhaps add to migration guide:
This behavior is different from how things worked in Pydantic V1, where we would always include all (subclass) fields when recursively dumping models to dicts. The motivation behind this change in behavior is that it helps ensure that you know precisely which fields could be included when serializing, even if subclasses get passed when instantiating the object. In particular, this can help prevent surprises when adding sensitive information like secrets as fields of subclasses.
Thanks so much!
Example Code
No response
Python, Pydantic & OS Version
Selected Assignee: @dmontagu
The text was updated successfully, but these errors were encountered: