Support for serialize_as_any runtime setting#8830
Merged
sydney-runkle merged 10 commits intomainfrom Mar 25, 2024
Merged
Conversation
Deploying pydantic-docs with
|
| Latest commit: |
3183633
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0f66733c.pydantic-docs2.pages.dev |
| Branch Preview URL: | https://ser-as-any-support.pydantic-docs2.pages.dev |
CodSpeed Performance ReportMerging #8830 will not alter performanceComparing Summary
|
Contributor
Author
|
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":"**********"}} |
Contributor
Author
|
Please review |
serialize_as_any config and runtime settingsserialize_as_any runtime setting
dmontagu
reviewed
Mar 13, 2024
dmontagu
reviewed
Mar 13, 2024
dmontagu
reviewed
Mar 13, 2024
dmontagu
reviewed
Mar 13, 2024
dmontagu
reviewed
Mar 13, 2024
dmontagu
reviewed
Mar 13, 2024
dmontagu
approved these changes
Mar 13, 2024
Contributor
dmontagu
left a comment
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6423
Counterpart PR: pydantic/pydantic-core#1194
Requires new
pydantic-corerelease in order to support the new runtime flag 👍. Leaving WIP tag until we release a newpydantic-coreversion with the necessary changes!TODO:
TypeAdapterSelected Reviewer: @davidhewitt