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")
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 raiseValidationError
, and the dict is a surprise to the users of the fieldPossible solution
Raise ValidationError if nothing in the Union matches.
Alternatives
For now, I have added to the object
Context
No response