Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
changhc wants to merge4 commits intopydantic:main
base:main
Choose a base branch
Loading
fromchanghc:8722-validate-default

Conversation

changhc
Copy link
Contributor

@changhcchanghc commentedDec 23, 2024
edited by pydantic-hookybot
Loading

Change Summary

Extended optionvalidate_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 ofTrue/False does not change with this PR.

Note that even thoughinit 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

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with thispydantic-core (except for expected changes)
  • My PR is ready to review,please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer:@davidhewitt

@codecovCodecov
Copy link

codecovbot commentedDec 23, 2024
edited
Loading

Codecov Report

Attention: Patch coverage is89.47368% with8 lines in your changes missing coverage. Please review.

Files with missing linesPatch %Lines
src/validators/with_default.rs89.18%8 Missing⚠️

📢 Thoughts on this report?Let us know!

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedDec 23, 2024
edited
Loading

CodSpeed Performance Report

Merging#1593 willnot alter performance

Comparingchanghc:8722-validate-default (1a82948) withmain (562fad3)

Summary

✅ 157 untouched benchmarks

@changhcchanghc marked this pull request as ready for reviewDecember 23, 2024 23:26
@changhc
Copy link
ContributorAuthor

please review

pydantic-hooky[bot] and psychedelicious reacted with thumbs up emoji

@psychedelicious
Copy link

Thank you! The problem this addresses has been a persistent thorn in our sides. Would love to see this released.

psychedelicious added a commit to invoke-ai/InvokeAI that referenced this pull requestMay 2, 2025
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
psychedelicious added a commit to invoke-ai/InvokeAI that referenced this pull requestMay 13, 2025
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
psychedelicious added a commit to invoke-ai/InvokeAI that referenced this pull requestMay 13, 2025
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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees

@davidhewittdavidhewitt

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@changhc@psychedelicious@davidhewitt

[8]ページ先頭

©2009-2025 Movatter.jp