Raise RequestValidationError on ValueError from a Depedency#9314
Raise RequestValidationError on ValueError from a Depedency#93141337vida wants to merge 10 commits intofastapi:masterfrom
Conversation
|
📝 Docs preview for commit 1d1834b at: https://641f778f3b348622ddf839ad--fastapi.netlify.app |
|
📝 Docs preview for commit cb666a6 at: https://641f7b01adf9c120a66d41a3--fastapi.netlify.app |
|
LGTM |
YuriiMotov
left a comment
There was a problem hiding this comment.
@1337vida, thanks for your interest and efforts!
I agree that it would be nice to provide an easy way to raise RequestValidationError from inside the dependency. But I think it should be done in different way.
Sometimes you may have dependencies that use Pydantic models internally (e.g. to extract data from DB and validate it) and they may also raise ValueError.
Such errors aren't user-errors and we shouldn't return 422 error response for them, but rather 500 server error response.
|
As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR. |
Adds the same functionality as @validator from PyDantic to Headers, Cookies, Path and Query params.