This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Exception handler exception for response ValidationError with non-pydantic model #1275
Comments
for what it's worth this appears to be an upstream bug in pydantic edit: OK, maybe not a bug in pydantic; from what I can tell this is from incorrect use of an internal pydantic method (
anyway, the code in question is in
it may be worthwhile to replace the for now I've had success monkey-patching
... and
|
@ATRI2107 I think your issue is unrelated - your response doesn't match what you have defined in your response_model |
Anyone running into this from google, if you haven't seen this before and are suddenly getting it after upgrading to >=0.80 it may be because of the response model validation change. |
I ran into this issue after upgrading to To be fair, if I had static type checking enabled in my dev environment (which I found out I didn't while debugging this issue), that would have caught the incorrect return type annotation first. But I think it would still be nice to have a less opaque error for people new to fasapi, such as myself. |
@tiangolo any thoughts re: my previous comment? #1275 (comment) |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
FastAPI will raise a ValidationError for the invalid response and set the field type. This can go wrong if the response model is not a
pydantic
model (ordataclass
). When trying to produce the string representation of the exception,pydantic
will try to produce the errors and fail because of the field type passed into theValidationError
not being aBaseModel
orDataclassType
. I am not sure if we need something like aResponseValidationError
to prevent this issue. Or maybe I am missing something else?To Reproduce
Steps to reproduce the behavior with a minimum self-contained file.
Replace each part with your own scenario:
/
.Expected behavior
I expected it to return
{"detail": "Unexpected error occurred: <exception string>"}
. Even though the endpoint code is clearly wrong, I would hope that I would be able to log and return the resulting error instead of the exception being raised and receiving the default 500 response.Environment
The text was updated successfully, but these errors were encountered: