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

squash __root__ in BaseModel json encoding #1524

Merged
merged 1 commit into from Jun 13, 2020

Conversation

patrickkwang
Copy link
Contributor

Fixes #911.

This corrects the specific problem described by @peku33, where the response is received by the client as {"__root__": foo}. This change simply converts to foo during json encoding.

Note that these __root__ structures may still exist internally, e.g. {"foo": {"__root__": foo}}. That is a pydantic bug (pydantic/pydantic#1414) with an open PR.

@codecov
Copy link

codecov bot commented Jun 6, 2020

Codecov Report

Merging #1524 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1524   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          227       227           
  Lines         6810      6817    +7     
=========================================
+ Hits          6810      6817    +7     
Impacted Files Coverage Δ
fastapi/encoders.py 100.00% <100.00%> (ø)
tests/test_jsonable_encoder.py 100.00% <100.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 a0e4d38...d123a9a. Read the comment docs.

@tiangolo tiangolo merged commit 8fb7557 into tiangolo:master Jun 13, 2020
@tiangolo
Copy link
Owner

Nice, 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.

Pydantic __root__ model - incorrect handling
2 participants