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

Fix bugs that arise from deserializing dicts with Unions of Instance properties #228

Merged
merged 8 commits into from
Mar 29, 2018

Conversation

fwkoch
Copy link
Contributor

@fwkoch fwkoch commented Mar 21, 2018

Deserializing when a Union of Instance properties is present results in unwanted behavior. '__class__' was ignored even when that class was a valid choice, and dictionaries were filtered to be empty to match one class, rather than selecting a different class.

Now, deserialize has additional kwargs:

  • strict - this requires __class__ to match the deserialized instance AND disallows extra properties in the input dictionary
  • assert_valid - deserialization fails if the resulting instance is invalid.

To maintain backwards compatibility, both of these are False by default, but to fix the above Union bugs, they are True by default when deserializing the Union property. You can keep the current, lenient behavior of Union properties by setting strict_instances=True on the Union property.

@fwkoch fwkoch requested review from ismacaulay and bsmithyman March 21, 2018 19:28
@codecov
Copy link

codecov bot commented Mar 21, 2018

Codecov Report

Merging #228 into dev will increase coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #228      +/-   ##
==========================================
+ Coverage   95.35%   95.44%   +0.08%     
==========================================
  Files          17       17              
  Lines        2241     2259      +18     
==========================================
+ Hits         2137     2156      +19     
+ Misses        104      103       -1
Impacted Files Coverage Δ
properties/extras/singleton.py 97.36% <100%> (ø) ⬆️
properties/base/base.py 99.1% <100%> (+0.01%) ⬆️
properties/base/union.py 97.87% <100%> (+1.02%) ⬆️

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 ffde268...26d2806. Read the comment docs.

@fwkoch
Copy link
Contributor Author

fwkoch commented Mar 21, 2018

This also removes verbose on deserialize - We are now more opinionated, strict=True raises errors where verbose raised warnings.

@fwkoch fwkoch changed the base branch from feat/singletons to dev March 29, 2018 08:03
@fwkoch fwkoch merged commit 096aa3e into dev Mar 29, 2018
@fwkoch fwkoch deleted the fix/union_deserialization branch March 29, 2018 08:14
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.

1 participant