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 parsing nested custom root type models #1253

Merged

Conversation

Shados
Copy link
Contributor

@Shados Shados commented Feb 25, 2020

Change Summary

When validating fields that are pydantic models, if all else fails explicitly check if __custom_root_type__ is true, and try to parse_obj if it is.

Related issue number

Fixes #1190.

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)

@Shados Shados force-pushed the fix-nested-custom-root-type-models branch from 370eaef to 74fecb3 Compare February 25, 2020 03:55
@codecov
Copy link

codecov bot commented Feb 25, 2020

Codecov Report

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

@@             Coverage Diff             @@
##            master    #1253      +/-   ##
===========================================
- Coverage   100.00%   99.89%   -0.11%     
===========================================
  Files           21       21              
  Lines         3666     3708      +42     
  Branches       718      731      +13     
===========================================
+ Hits          3666     3704      +38     
- Misses           0        2       +2     
- Partials         0        2       +2     
Impacted Files Coverage Δ
pydantic/utils.py 98.92% <0.00%> (-1.08%) ⬇️
pydantic/schema.py 99.44% <0.00%> (-0.56%) ⬇️
pydantic/color.py 100.00% <0.00%> (ø)
pydantic/fields.py 100.00% <0.00%> (ø)
pydantic/typing.py 100.00% <0.00%> (ø)
pydantic/validators.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 645e5fe...92a7e3d. Read the comment docs.

@Shados Shados force-pushed the fix-nested-custom-root-type-models branch 2 times, most recently from e625165 to fd0a670 Compare February 25, 2020 05:00
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.

looks like we still don't have a test for nested root models like i put on the issue.

Otherwise LGTM.

@Shados
Copy link
Contributor Author

Shados commented Feb 25, 2020

looks like we still don't have a test for nested root models like i put on the issue.

Otherwise LGTM.

Not sure which you mean. I do have the example parse_as_obj case included. I guess I could split that out into its own test?

@samuelcolvin
Copy link
Member

There's still no explicit test for a custom root type as as the type of a custom root type:

from pydantic import BaseModel

class Foo(BaseModel):
    __root__: Dict[str, int]

class Bar(BaseModel):
    __root__: Foo

@Shados Shados force-pushed the fix-nested-custom-root-type-models branch from fd0a670 to 92a7e3d Compare March 13, 2020 02:38
@Shados
Copy link
Contributor Author

Shados commented Mar 13, 2020

@samuelcolvin I have no idea why anyone would want do that explicitly, but I've added a test covering it.

@samuelcolvin samuelcolvin merged commit d1279e8 into pydantic:master Mar 17, 2020
@samuelcolvin
Copy link
Member

thanks so much.

RajatRajdeep pushed a commit to RajatRajdeep/pydantic that referenced this pull request May 14, 2024
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

Broken loading list of tuples.
2 participants