- Notifications
You must be signed in to change notification settings - Fork293
Validate default values at schema definition#1593
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecovbot commentedDec 23, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report?Let us know! |
codspeed-hqbot commentedDec 23, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#1593 willnot alter performanceComparing Summary
|
please review |
psychedelicious commentedMay 2, 2025
Thank you! The problem this addresses has been a persistent thorn in our sides. Would love to see this released. |
This prevents issues where the node is defined with an invalid default value, which would guarantee an error during a ser/de roundtrip.- Upstream issue requesting this functionality be built-in to pydantic:pydantic/pydantic#8722- Upstream PR that implements the functionality:pydantic/pydantic-core#1593
This prevents issues where the node is defined with an invalid default value, which would guarantee an error during a ser/de roundtrip.- Upstream issue requesting this functionality be built-in to pydantic:pydantic/pydantic#8722- Upstream PR that implements the functionality:pydantic/pydantic-core#1593
This prevents issues where the node is defined with an invalid default value, which would guarantee an error during a ser/de roundtrip.- Upstream issue requesting this functionality be built-in to pydantic:pydantic/pydantic#8722- Upstream PR that implements the functionality:pydantic/pydantic-core#1593
Uh oh!
There was an error while loading.Please reload this page.
Change Summary
Extended option
validate_default
so that it's possible to validate default values when a model schema is being built.This option now can be a boolean or 3 possible string values:
'never'
,'definition'
, or'init'
.never
: no validation for default values at all. This is the same asFalse
.init
: validation at model instantiation. This is the same asTrue
.definition
: validation at model definition.The behaviour of
True
/False
does not change with this PR.Note that even though
init
anddefinition
are not mutually exclusive and I implemented these as flags that can co-exist, I decided not to add another option, e.g.always
, that cover both flags because if a validation is raised at model definition, it's pretty much impossible to trigger such error at model instantiation because the model does not built at all and therefore we don't really needalways
.Related issue number
Part ofpydantic/pydantic#8722
Checklist
pydantic-core
(except for expected changes)Selected Reviewer:@davidhewitt