fastapi icon indicating copy to clipboard operation
fastapi copied to clipboard

:safety_vest: Update implementarion and docs for RequestValidationError in pydantic v2

Open tamird opened this issue 9 months ago • 25 comments

Update the documentation to explain that RequestValidationError isn't literally a subclass since Pydantic V2.

Closes #10424. Closes #11176.

tamird avatar May 06 '24 22:05 tamird

📝 Docs preview for commit aa59b77ac27f4ef842be10d8e7be9957f6478c43 at: https://69746e9e.fastapitiangolo.pages.dev

tiangolo avatar May 06 '24 22:05 tiangolo

📝 Docs preview for commit 25da9fdc0af2f3249acd7b32fee94a59086bbc78 at: https://a9ca36dc.fastapitiangolo.pages.dev

tiangolo avatar May 06 '24 23:05 tiangolo

📝 Docs preview for commit 45a560a69c4a02da61678a82e77ac427dc88f177 at: https://787fcba4.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 00:05 tiangolo

📝 Docs preview for commit 338a33e2b9eecb9138d29fa470634b279c5956d0 at: https://5e014aa1.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 16:05 tiangolo

@tiangolo this is green now. I believe it is technically a breaking change.

tamird avatar May 07 '24 17:05 tamird

📝 Docs preview for commit 796e817091c08dbcfc530512965f38873ea0ae86 at: https://7516403b.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 17:05 tiangolo

📝 Docs preview for commit de154678a1f2fd8789166c50ba4ed95427861e31 at: https://b04b1a0e.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 18:05 tiangolo

📝 Docs preview for commit 30788f5cffae8fd2c9e00258b4b194d56c20b011 at: https://18f55b1d.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 18:05 tiangolo

📝 Docs preview for commit f1b3e2ff0ef65d1da795987b2bfc8051ea1b2479 at: https://d5332d85.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 18:05 tiangolo

📝 Docs preview for commit 11aca70a419392f1b37b1e6e65070be7d0f8fd93 at: https://a014911b.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 18:05 tiangolo

📝 Docs preview for commit edca75902fc452fa9090a169feb83a49f99186b8 at: https://9fa0665c.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 19:05 tiangolo

📝 Docs preview for commit 025ef5fd714f8f0268ca9dd81a281947393bcb6f at: https://3e363dc1.fastapitiangolo.pages.dev

tiangolo avatar May 07 '24 21:05 tiangolo

📝 Docs preview for commit b91428de008aa0c79729006068021b84d1575feb at: https://b683ce8c.fastapitiangolo.pages.dev

tiangolo avatar May 10 '24 09:05 tiangolo

@tiangolo ping - would you mind having a look please?

tamird avatar May 10 '24 09:05 tamird

@alejsdev could you please have a look? What is the process for getting a review?

tamird avatar May 20 '24 19:05 tamird

@tiangolo ping

tamird avatar Jun 17 '24 21:06 tamird

I think this PR will actually fix the issue I described here: https://github.com/fastapi/fastapi/discussions/11923

The extra input and ctx fields that come out of pydantic v2 ValidationError.errors() is causing problems when serializing that data back in fastapi.

bertomaniac avatar Aug 08 '24 14:08 bertomaniac

3 months and no review :(

tamird avatar Aug 08 '24 14:08 tamird

Dang, I just checked out your PR and tried it for my test. It doesn't fix it because I think this code block still needs to strip out ctx and input from pydantic v2s ValidationError.errors() call:

            except ValidationError as exc:
                errors: List[ErrorDetails] = [
                    {**err, "loc": loc + err.get("loc", ())}  # type: ignore [typeddict-unknown-key]
                    for err in exc.errors(include_url=False)
                ]
                return None, errors

perhaps

for err in exc.errors(include_url=False, include_input=False, include_context=False)

See here in pydantic docs: https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ValidationError.errors

bertomaniac avatar Aug 08 '24 15:08 bertomaniac

Hi @tamird 👋

We'll be reviewing this PR soon. 🤓

Thank you for your interest and time in helping us with your contribution 🙇

estebanx64 avatar Aug 31 '24 04:08 estebanx64

📝 Docs preview for commit 3f38cf372997e15ebeca5dff4388fd6654fea3d9 at: https://5ba594db.fastapitiangolo.pages.dev

Modified Pages

  • https://5ba594db.fastapitiangolo.pages.dev/tutorial/handling-errors/

github-actions[bot] avatar Sep 30 '24 20:09 github-actions[bot]

I have rebased this to resolve the merge conflicts.

tamird avatar Sep 30 '24 20:09 tamird

📝 Docs preview for commit 39429c16d17c5be4769e8b1e8f07454a14b11c06 at: https://e052a695.fastapitiangolo.pages.dev

Modified Pages

  • https://e052a695.fastapitiangolo.pages.dev/tutorial/handling-errors/

github-actions[bot] avatar Sep 30 '24 20:09 github-actions[bot]

@estebanx64 ping.

tamird avatar Oct 08 '24 13:10 tamird