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

Deserialization fails for Optional[Dict[...]] #47

Closed
alexmikoto opened this issue Dec 20, 2019 · 0 comments
Closed

Deserialization fails for Optional[Dict[...]] #47

alexmikoto opened this issue Dec 20, 2019 · 0 comments
Labels
type: bug Something isn't working

Comments

@alexmikoto
Copy link

alexmikoto commented Dec 20, 2019

Trying to deserialize a nullable Dict[T, U] results in get_dict_parser being called anyway and raising an AttributeError due to the target dict being None.

Testing with Python 3.7 and dataclass_factory 2.4.1 the following code will raise:

from typing import Optional, Dict, Any
from dataclass_factory import Factory

@dataclass
class Test:
    x: Optional[Dict[str, Any]]

f = Factory()
f.load({"x": None}, Test)

The root issue seems to be that Optional is not being detected correctly as it is indistinguishable from Union[T, NoneType], which ends up in get_dict_parser raising due to the order of the type arguments.

Tishka17 added a commit that referenced this issue Dec 20, 2019
Tishka17 added a commit that referenced this issue Dec 20, 2019
@Tishka17 Tishka17 added the type: bug Something isn't working label Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants