Skip to content

Conversation

masalim2
Copy link
Contributor

@masalim2 masalim2 commented Dec 18, 2020

Change Summary

If a user forgot to return the values dict in a root validator, they'd see a somewhat opaque exception:

TypeError: __dict__ must be set to a dictionary, not a 'NoneType'`.  

Added a quick check in BaseModel.__init__ to raise a more user-friendly hint in the TypeError:

TypeError: BaseModel.__init__ received `None` values. Are you forgetting to return `values` in a root validator?

Related issue number

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)

@codecov
Copy link

codecov bot commented Dec 18, 2020

Codecov Report

Merging #2209 (610450a) into master (3496a47) will decrease coverage by 0.06%.
The diff coverage is n/a.

@@             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     
Impacted Files Coverage Δ
pydantic/types.py 100.00% <0.00%> (ø)
pydantic/utils.py 100.00% <0.00%> (ø)
pydantic/errors.py 100.00% <0.00%> (ø)
pydantic/fields.py 100.00% <0.00%> (ø)
pydantic/schema.py 100.00% <0.00%> (ø)
pydantic/typing.py 100.00% <0.00%> (ø)
pydantic/generics.py 100.00% <0.00%> (ø)
pydantic/networks.py 100.00% <0.00%> (ø)
pydantic/decorator.py 100.00% <0.00%> (ø)
pydantic/validators.py 100.00% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3496a47...610450a. Read the comment docs.

Copy link
Member

@samuelcolvin samuelcolvin left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks unrelated.

Copy link
Collaborator

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)

Copy link
Collaborator

@PrettyWood PrettyWood left a 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?

@PrettyWood PrettyWood added the awaiting author revision awaiting changes from the PR author label Jan 19, 2021
@@ -0,0 +1 @@
User-friendly TypeError when a `root_validator` returns `None`.
Copy link
Collaborator

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 TypeError when a root_validator does not return a dict (e.g. None).

Otherwise LGTM 👍

@PrettyWood PrettyWood added ready for review and removed awaiting author revision awaiting changes from the PR author labels Jan 19, 2021
@samuelcolvin samuelcolvin merged commit dcc00be into pydantic:master Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants