You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the FastAPI documentation, with the integrated search.
I already searched in Google "How to X in FastAPI" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI.
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
asyncdefvalidation_exception_handler(
request: Request,
exc: RequestValidationError,
) ->AesResponse:
error=exc.errors()[0]
error_type=error["type"]
ctx=error.get("ctx", {})
field_name=error["loc"][-1]
model: BaseModel# want to get from RequestValidationErrorfield_title=get_field_title_from_model(model, field_name)
returnAesResponse(
content=Resp(
code=ResponseCodeEnum.failed,
message=f"{field_title}:{error["msg"]}",
data=exc.errors(),
).model_dump(),
)
Description
RequestValidationError before
RequestValidationError current
now cannot get the related pydantic model, which I can get FieldInfo from it, to customize the error message, such as use field title instead of the field_name to show the human readable message. But now its impossible, how can I implemented this like before.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
RequestValidationError before
![image](https://private-user-images.githubusercontent.com/42133281/340163020-a731bf3c-d1ed-4f90-a789-37df8e9ac62d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAxNjg0ODEsIm5iZiI6MTcyMDE2ODE4MSwicGF0aCI6Ii80MjEzMzI4MS8zNDAxNjMwMjAtYTczMWJmM2MtZDFlZC00ZjkwLWE3ODktMzdkZjhlOWFjNjJkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1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WUyMTAxNGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.k6zdlZjEiduAze-q_SEFTL8TQDnir1EzOcsMuQ5im_g)
RequestValidationError current
now cannot get the related pydantic model, which I can get FieldInfo from it, to customize the error message, such as use field title instead of the field_name to show the human readable message. But now its impossible, how can I implemented this like before.
Operating System
macOS
Operating System Details
14.3.1 (23D60)
FastAPI Version
0.111.0
Pydantic Version
2.7.4
Python Version
Python 3.11.7
Additional Context
No Additional Context
Beta Was this translation helpful? Give feedback.
All reactions