Thanks to visit codestin.com
Credit goes to github.com

Skip to content

squash __root__ in BaseModel json encoding#1524

Merged
tiangolo merged 1 commit into
fastapi:masterfrom
patrickkwang:root_encoding
Jun 13, 2020
Merged

squash __root__ in BaseModel json encoding#1524
tiangolo merged 1 commit into
fastapi:masterfrom
patrickkwang:root_encoding

Conversation

@patrickkwang

Copy link
Copy Markdown
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

codecov Bot commented Jun 6, 2020

Copy link
Copy Markdown

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 fastapi:master Jun 13, 2020
@tiangolo

Copy link
Copy Markdown
Member

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