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

Replace Pydantic ValueError with standard ValueError #6

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

spwoodcock
Copy link
Member

The current implementation of pydantic_core.ValidationError did not work.
If the except was triggered here

        try:
            user_data = deserializer.loads(decoded_token)
        except (SignatureExpired, BadSignature) as e:

we simply got: no constructor defined.

This is because pydantic ValidationError cannot be used directly.

Correct usage would be via the from_exception_data static method:

raise ValidationError.from_exception_data(
                {
                    "type": "value_error",
                    "loc": ("access_token",),
                    "input": access_token,
                    "ctx": {
                        "error": "Auth token is invalid or expired",
                    },
                }
            )

However, IMO, this is overly complicated and we don't need to use pydantic for it.
A simple ValueError will suffice & is more maintainable.

Additional context

  • We only use Pydantic for two very simple models.
  • Pydantic could probably be refactored out eventually, reducing the dependencies required to install this package.

@spwoodcock spwoodcock added the bug Something isn't working label Apr 8, 2024
@spwoodcock spwoodcock self-assigned this Apr 8, 2024
@spwoodcock spwoodcock merged commit c35f5a5 into main Apr 10, 2024
1 check failed
@spwoodcock spwoodcock deleted the fix/pydantic-validation-error branch April 10, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant