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
Support for serialize_as_any
runtime setting
#8830
Conversation
Deploying pydantic-docs with Cloudflare Pages
|
CodSpeed Performance ReportMerging #8830 will not alter performanceComparing Summary
|
Note, I wanted to experiment a bit with how a user of from pydantic import BaseModel, SecretStr
class MyBaseModel(BaseModel):
def model_dump(self, **kwargs):
# use super's model_dump, with serialize_as_any set to True by default
return super().model_dump(serialize_as_any=True, **kwargs)
def model_dump_json(self, **kwargs):
# use super's model_dump_json, with serialize_as_any set to True by default
return super().model_dump_json(serialize_as_any=True, **kwargs)
class User(BaseModel):
name: str
class UserInfo(User):
password: SecretStr
class OuterModel(MyBaseModel):
user: User
u = OuterModel(user=UserInfo(name='John', password='secret_pw'))
print(u.model_dump_json())
#> {"user":{"name":"John","password":"**********"}} |
Please review |
serialize_as_any
config and runtime settingsserialize_as_any
runtime setting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good other than the docs suggestions (which you can take or leave), assuming the pydantic-core PR is good etc.
serialize_as_any
runtime settingserialize_as_any
runtime setting
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
10ca367
to
3183633
Compare
Closes #6423
Counterpart PR: pydantic/pydantic-core#1194
Requires new
pydantic-core
release in order to support the new runtime flag 👍. Leaving WIP tag until we release a newpydantic-core
version with the necessary changes!TODO:
TypeAdapter
Selected Reviewer: @davidhewitt