Skip to content
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

RequestValidationError is **not** a sub-class of Pydantic's ValidationError #10786

Closed
9 tasks done
Kludex opened this issue Dec 16, 2023 Discussed in #10421 · 3 comments
Closed
9 tasks done

RequestValidationError is **not** a sub-class of Pydantic's ValidationError #10786

Kludex opened this issue Dec 16, 2023 Discussed in #10421 · 3 comments
Labels
docs Documentation about how to use FastAPI question Question or problem

Comments

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Dec 16, 2023

Discussed in #10421

Originally posted by valentinoli October 10, 2023

First Check

  • I added a very descriptive title here.
  • 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

@app.exception_handler(ValidationError)
async def validation_exception_handler(request: Request, exc: ValidationError):
    return PlainTextResponse(
        str(exc), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
    )

Description

I was trying to handle both RequestValidationError and ValidationError by writing a custom handler for ValidationError but that doesn't work.

The docs state that

RequestValidationError is a sub-class of Pydantic's ValidationError

However, looking at FastAPI source code reveals that this is not the case.

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.101.0

Pydantic Version

2.1.1

Python Version

3.11.3

Additional Context

No response

@Kludex Kludex added question Question or problem docs Documentation about how to use FastAPI labels Dec 16, 2023
@Kludex
Copy link
Sponsor Collaborator Author

Kludex commented Dec 16, 2023

The documentation needs to be fixed. The RequestValidationError was a subclass of ValidationError before 0.100.0 - it's not the case anymore.

@sanzoghenzo
Copy link

Duplicate of #10424 😉

@Kludex
Copy link
Sponsor Collaborator Author

Kludex commented Dec 18, 2023

Ah. I forgot. Thanks.

@Kludex Kludex closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2023
Mkznd added a commit to Mkznd/fastapi that referenced this issue Feb 21, 2024
…class of Pydantic ValidationError, according to issue tiangolo#10786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI question Question or problem
Projects
None yet
Development

No branches or pull requests

2 participants