-
Notifications
You must be signed in to change notification settings - Fork 10
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
Error when loading a field with typing.Any and value None #96
Comments
Thanks @sveinse. This raises a question. Currently if typ == t.Any:
field.allow_none = True we can do that. But I'm not certain that |
In the context of serializers, The reason I encountered this bug is because I have a data class with an extra internal field which is excluded from the schema. However due to #97 I must declare an arbitrary typing hint on this field. |
This issue is also visible in container uses, such as list and tuples: @dataclasses.dataclass
class Data:
x: List[Any] which also results in deserialization error @dataclasses.dataclass
class Data:
x: List[Optional[Any]] However it doesn't feel elegant having to use the typing hint |
The first thing that comes to my mind for your containers is that they should be generic like other containers and thus instances would actually have a specific type. Though, that probably doesn't really solve anything. The generic form where you haven't figured out what is in it would I guess be My gut says that if we are mapping |
It might be a little OT for the issue, but please let me give an overview of why I think we must consider this: The reason for having POS = Union[Tuple[str, str, float], str, None]
pan: Tuple[POS, POS] I.e. the It might be argued that this is mapping too many variants into the same field. I haven't really found a good way to represent this type of composite object. One method might be to decompose the variants into multiple fields: pan_if_2: Optional[str]
pan_if_3: Optional[Tuple(str, str, float)] I'm not sure I find this elegant. In this application |
The following test generates an Validation error when the type hint
typing.Any
is used for a field and the de-serializer is given the value ofNone
. From reading the py docs, I think thetyping.Any
hint intends to also cover None. The current workaround is to uset.Optional[t.Any]
.Is this perhaps a Marshmallow issue?
The text was updated successfully, but these errors were encountered: