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

[FEATURE] Raise ValidationError if JSON doesn't match any of the types in Union #522

Open
PatrickF1 opened this issue Mar 5, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@PatrickF1
Copy link

Description

The current behavior of decoding Union types with from_dict is if none of the types in the Union matches, then the field becomes a dict. To me, I would have expected it to raise ValidationError, and the dict is a surprise to the users of the field

Possible solution

Raise ValidationError if nothing in the Union matches.

Alternatives

For now, I have added to the object

def __post_init__(self) -> None:
    if isinstance(self.params, dict):
        raise Exception("params is missing some fields")

Context

No response

@PatrickF1 PatrickF1 added the enhancement New feature or request label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant