Skip to content
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

check ModelField().validate_always when inheriting #1545

Merged
merged 3 commits into from Jun 29, 2020

Conversation

dcHHH
Copy link
Contributor

@dcHHH dcHHH commented May 21, 2020

Change Summary

Indeed, the bug is originated from the change main.py:169. The fields of C is a deepcopy of it's parent class, so C.value_b.validate_always = B.value_b.validate_always = False
https://github.com/samuelcolvin/pydantic/blob/1eeb225c67f1131f948c5f129f5c2e56a4c2c6b7/pydantic/main.py#L881-L883
So value_b is not validated. Just move the assignment of validate_always from self.prepare() to self.populate_validators(), then the bug is solved.

Related issue number

#1155

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 May 21, 2020

Codecov Report

Merging #1545 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##            master    #1545      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           21       21              
  Lines         3772     3803      +31     
  Branches       749      756       +7     
===========================================
+ Hits          3772     3801      +29     
- Misses           0        1       +1     
- Partials         0        1       +1     
Impacted Files Coverage Δ
pydantic/fields.py 100.00% <ø> (ø)
pydantic/networks.py 99.21% <0.00%> (-0.79%) ⬇️
pydantic/types.py 100.00% <0.00%> (ø)
pydantic/errors.py 100.00% <0.00%> (ø)
pydantic/schema.py 100.00% <0.00%> (ø)
pydantic/typing.py 100.00% <0.00%> (ø)
pydantic/validators.py 100.00% <0.00%> (ø)
pydantic/dataclasses.py 100.00% <0.00%> (ø)
pydantic/env_settings.py 100.00% <0.00%> (ø)
... and 1 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 1eeb225...0d5caf2. Read the comment docs.

@samuelcolvin
Copy link
Member

Please use a descriptive title on the PR.

@dcHHH dcHHH changed the title fix issure #1155 check ModelField().validate_always when inheriting May 23, 2020
@dcHHH
Copy link
Contributor Author

dcHHH commented May 23, 2020

Please use a descriptive title on the PR.

This is my first PR. Sorry for the inconvenience I made. And the Change Summary of this PR is the reply to #1155 (comment)

@samuelcolvin
Copy link
Member

Looks good, please can you add a change file describing this change.

@samuelcolvin samuelcolvin merged commit 3a00e58 into pydantic:master Jun 29, 2020
sthagen pushed a commit to sthagen/pydantic-pydantic that referenced this pull request Jun 29, 2020
fix pydantic#1155

* fix issure pydantic#1155

* add changes.1545-dcHHH.md

* improve change description

Co-authored-by: dchhh <hudacong@geetest.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
sthagen pushed a commit to sthagen/pydantic-pydantic that referenced this pull request Jun 29, 2020
* fix issure pydantic#1155

* add changes.1545-dcHHH.md

* improve change description

Co-authored-by: dchhh <hudacong@geetest.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
@Bobronium Bobronium mentioned this pull request Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants