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

Enhancement: Add Pydantic's error dictionary to ValidationException's extra dict #3466

Open
Anu-cool-007 opened this issue May 4, 2024 · 0 comments · May be fixed by #3467
Open

Enhancement: Add Pydantic's error dictionary to ValidationException's extra dict #3466

Anu-cool-007 opened this issue May 4, 2024 · 0 comments · May be fixed by #3467
Labels
Enhancement This is a new feature or request

Comments

@Anu-cool-007
Copy link

Anu-cool-007 commented May 4, 2024

Summary

To send a custom message for Pydantic errors, we require the error type. Pydantic's error details are lost while building the error message in SignatureModel._build_error_message. If we add the exc dict to this message, it will be propagated to exception handlers

Basic Example

"SignatureModel"
@classmethod
    def _build_error_message(
        cls,
        keys: Sequence[str],
        exc_msg: str,
        connection: ASGIConnection,
        exc: Optional[Dict[str, Any]] = None
    ) -> ErrorMessage:
    ...
    if exc:
        message["exc"] = exc
    ...

Then in an exception handler, Pydantic's error dict can be accessed by:
validation_exception["extra"][0]["exc"]

Drawbacks and Impact

No response

Unresolved questions

Is there a better way to propagate Pydantic's error object to ValidationException received by the handlers?


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@Anu-cool-007 Anu-cool-007 added the Enhancement This is a new feature or request label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This is a new feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant