Model's @field_validator unable to catch ValidationError during deserialization of query params #11783
Unanswered
ErikBratkov
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Run test_validators with unittest or pytest. The last assert statement will fail, but normally the second assert statement should fail.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.111.0
Pydantic Version
2.7.4
Python Version
3.11.9
Additional Context
I make deep customizations to Pydantic models, and it is crucial for me that the field_validator decorator works in the same manner for different usages in FastAPI.
P.S. The demonstrated code is very simple and doesn't show what I'm really trying to do. Therefore, thanks for your kind efforts, but please don't waste your valuable time explaining how to catch a ValidationError without using field_validator. ;)
P.P.S. I know that it is possible to catch ValidationError by direct calling of deserialization function via Depends:
But this not that I want.
P.P.P.S. The same problem was discussed on Stack Overflow: https://stackoverflow.com/a/78116620. Unfortunately, the answerer did not explain how they discovered that Depends validates the model in a different way. I was unable to find the problem in FastApi source codes by myself (((
Beta Was this translation helpful? Give feedback.
All reactions