Closed cj-darius-lapunas closed 1 year ago
__post_deserialize__ hook causes deserialization errors with str or bool fields. Tested using DataClassDictMixin and Python versions 3.7-3.10.
__post_deserialize__
str
bool
DataClassDictMixin
Narrowed down the simplest repro I could.
@dataclass class Data(DataClassDictMixin): foo: str @classmethod def __post_deserialize__(cls, obj): return obj print(Data.from_dict({'foo': 'bar'}))
result:
Traceback (most recent call last): File "....", line 16, in <module> print(Data.from_dict({'foo': 'bar'})) File "<string>", line 13, in from_dict TypeError: __init__() missing 1 required positional argument: 'foo'
@dataclass class Data(DataClassDictMixin): foo: bool @classmethod def __post_deserialize__(cls, obj): return obj print(Data.from_dict({'foo': True}))
Traceback (most recent call last): File "....", line 16, in <module> print(Data.from_dict({'foo': True})) File "<string>", line 13, in from_dict TypeError: __init__() missing 1 required positional argument: 'foo'
@dataclass class Data(DataClassDictMixin): foo: int @classmethod def __post_deserialize__(cls, obj): return obj print(Data.from_dict({'foo': 5}))
Data(foo=5)
@dataclass class Data(DataClassDictMixin): foo: bool print(Data.from_dict({'foo': True}))
Data(foo=True)
@cj-darius-lapunas
Thank you for finding the bug so quickly. I fixed it and will release 3.8.1 today.
Fixed in 3.8.1
Looks good on my end, thanks for the quick fix.
Description
__post_deserialize__
hook causes deserialization errors withstr
orbool
fields. Tested usingDataClassDictMixin
and Python versions 3.7-3.10.What I Did
Narrowed down the simplest repro I could.
str example
result:
bool example
result:
int example
result:
no hook
result: