Skip to content

Raise RequestValidationError on ValueError from a Depedency#9314

Closed
1337vida wants to merge 10 commits intofastapi:masterfrom
1337vida:master
Closed

Raise RequestValidationError on ValueError from a Depedency#9314
1337vida wants to merge 10 commits intofastapi:masterfrom
1337vida:master

Conversation

@1337vida
Copy link

Adds the same functionality as @validator from PyDantic to Headers, Cookies, Path and Query params.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 1d1834b at: https://641f778f3b348622ddf839ad--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit cb666a6 at: https://641f7b01adf9c120a66d41a3--fastapi.netlify.app

@90
Copy link

90 commented Mar 25, 2023

LGTM

@tiangolo tiangolo added feature New feature or request investigate labels Oct 2, 2023
@alejsdev alejsdev added p4 and removed investigate labels Jan 15, 2024
Copy link
Member

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot closed this Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request p4 waiting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants