Replies: 3 comments
-
Workaround for now is to just return a starlette JSONResponse via
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I think you need from fastapi import FastAPI
from pydantic import BaseModel
class Blowup(BaseModel):
snake_case_fail: bool
class Config:
fields = {"snake_case_fail": "snakeCaseFail"}
allow_population_by_field_name = True
app = FastAPI()
@app.get("/mock/", response_model=Blowup)
async def test_failure() -> Blowup:
# Mock
mock_response = Blowup(snakeCaseFail=True)
return mock_response |
Beta Was this translation helpful? Give feedback.
0 replies
-
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
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
-
Describe the bug
In the
serialize_response
function of routing.py, field validation is performed on a dict from the model that does not respect the "by_alias" parameter. This results in a failure to properly validate required fields that have an alias defined in the Config.To Reproduce
/
.E pydantic.error_wrappers.ValidationError: 1 validation errors for Blowup
E response -> snakeCaseFail
E field required (type=value_error.missing)
response = response.dict(skip_defaults=skip_defaults)
to be:
response = response.dict(skip_defaults=skip_defaults, by_alias=by_alias)
results in successful validation and proper execution
Expected behavior
Expect the proper conversion via the alias to prevent validation error
Environment
OS: macOS
FastAPI Version 0.38.1
Python version, 3.7.4
Beta Was this translation helpful? Give feedback.
All reactions