-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Helpful TypeError when user forgets to return values in root valida…
#2209
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2209 +/- ##
===========================================
- Coverage 100.00% 99.93% -0.07%
===========================================
Files 21 22 +1
Lines 4121 4351 +230
Branches 829 875 +46
===========================================
+ Hits 4121 4348 +227
- Misses 0 3 +3
Continue to review full report at Codecov.
|
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 LGTM.
pydantic/main.py
Outdated
| object_setattr(__pydantic_self__, '__fields_set__', fields_set) | ||
| __pydantic_self__._init_private_attributes() | ||
|
|
||
| @no_type_check | ||
| @no_type_check # noqa: C901 (ignore complexity) |
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 looks unrelated.
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.
It's because of #2198 (review)
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.
@masalim2 Could you change the exception message?
changes/2209-masalim2.md
Outdated
| @@ -0,0 +1 @@ | |||
| User-friendly TypeError when a `root_validator` returns `None`. | |||
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.
Better add a verb at the beginning like
Raise a user-friendly
TypeErrorwhen aroot_validatordoes not return a dict (e.g.None).
Otherwise LGTM 👍
Change Summary
If a user forgot to return the
valuesdict in a root validator, they'd see a somewhat opaque exception:Added a quick check in
BaseModel.__init__to raise a more user-friendly hint in the TypeError:Related issue number
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)