BaseModel body validation can be bypassed if List is passed with extra parameters #6047
Replies: 2 comments
-
|
I met a similar problem, too. I post some info for frontend using react, antd and axios, but 422 code appeared before 200 code. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Works fine in current version |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Consider above code.
Endpoint
/answeraccepts data that should be of format{"id": str}Save above code as main.py and run with
uvicorn --factory main:create_app --port=8009 --reloadResponses from the following data are correct:
a)
{"id": "mock_id"}- 200b)
{"id": "mock_id", "invalid": 123}- 422 (extra not permitted)c)
[{"id": "mock_id"}]- 422 (value is not a valid dict)This is not correct behavior:
d)
[{"id": "mock_id", "invalid": 123}]- 200 - this should be an invalid input data (same as in c))Example curl POST request with invalid data that passes:
I tried to debug this and noticed that this line: https://github.com/tiangolo/fastapi/blob/0.88.0/fastapi/dependencies/utils.py#L696
does not return validation errors for d). I was not able to debug it deeper, as for some reason I could not break inside
ModelField::validatemethodUpon further inspection it turned out that
ModelFieldis part of pydantic's private API (similar issue as here: #1275 (comment)), so technically it could be a problem on pydantic's side, but can also mean that Fastapi is misusing that private api (and it's none of pydantic's business)Operating System
macOS
Operating System Details
No response
FastAPI Version
0.88.0
Python Version
3.10.8
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions