-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(validation): also check root_validators
when validate_assignment
is on
#1972
fix(validation): also check root_validators
when validate_assignment
is on
#1972
Conversation
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.
otherwise I'm good with this.
pydantic/main.py
Outdated
@@ -366,6 +366,16 @@ def __setattr__(self, name, value): | |||
elif self.__config__.validate_assignment: | |||
known_field = self.__fields__.get(name, None) | |||
if known_field: | |||
new_values = {**self.__dict__, name: value} | |||
|
|||
for skip_on_failure, validator in self.__post_root_validators__: |
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.
this should be called after validating the field and not all skip_on_failure
validators should be skipped.
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.
so it's more like standard validation.
a2effd0
to
7e8cc8c
Compare
@samuelcolvin You were right sorry I went too fast. I added both pre- and post-rootvalidators. The code is quite similar with |
👍 thank you |
🙏 thank you @PrettyWood and @samuelcolvin |
Change Summary
This is a proposal but I agree with @caldwellshane that
root_validator
should be considered as a regular validator. It should hence be triggered whenvalidate_assignment
is on.This is not the case at the moment
Related issue number
closes #1971
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)