Skip to content

Conversation

daviskirk
Copy link
Contributor

@daviskirk daviskirk commented Oct 9, 2020

Change Summary

In various places of the code, we compare directly to fields.Undefined
since we assume it to be constant.
When new models get created however, the object is deepcopied and
is no longer identical with the original object.
We therefore add __copy__ and __deepcopy__ methods to ensure
that the copied objects are actually the same original object.

Related issue number

While I did does not address the exact error message #1578 had, schema generation on inherited generics that had required generic fields did not work at all, so it might also fix this.

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)

@daviskirk daviskirk force-pushed the make-undefined-singleton branch 2 times, most recently from f93f560 to 5401afe Compare October 9, 2020 11:07
@codecov
Copy link

codecov bot commented Oct 9, 2020

Codecov Report

Merging #1981 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1981   +/-   ##
=======================================
  Coverage   99.84%   99.84%           
=======================================
  Files          42       42           
  Lines        7832     7850   +18     
  Branches     1576     1576           
=======================================
+ Hits         7820     7838   +18     
  Misses         10       10           
  Partials        2        2           
Impacted Files Coverage Δ
pydantic/fields.py 100.00% <100.00%> (ø)
pydantic/tools.py 100.00% <100.00%> (ø)
pydantic/types.py 100.00% <0.00%> (ø)
D:/a/pydantic/pydantic/pydantic/tools.py 100.00% <0.00%> (ø)
D:/a/pydantic/pydantic/pydantic/types.py 99.57% <0.00%> (ø)
D:/a/pydantic/pydantic/pydantic/fields.py 100.00% <0.00%> (ø)

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 dbb1ed0...f50e6d1. Read the comment docs.

…he code, we compare directly to `fields.Undefined`since we assume it to be constant.When new models get created however, the object is deepcopied andis no longer identical with the original object.We therefore add `__copy__` and `__deepcopy__` methods to ensurethat the copied objects are actually the same original object.
@daviskirk daviskirk force-pushed the make-undefined-singleton branch from 5401afe to f50e6d1 Compare October 9, 2020 11:16
@samuelcolvin samuelcolvin merged commit 30ee8e2 into pydantic:master Oct 9, 2020
@samuelcolvin
Copy link
Member

great, thank you.

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.

2 participants