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

__post_deserialize__ broken on str, bool #120

Closed
cj-darius-lapunas opened this issue Jun 23, 2023 · 3 comments · Fixed by #121
Closed

__post_deserialize__ broken on str, bool #120

cj-darius-lapunas opened this issue Jun 23, 2023 · 3 comments · Fixed by #121
Labels
bug Something isn't working

Comments

@cj-darius-lapunas
Copy link

  • mashumaro version: 3.8
  • Python version: 3.7-3.10
  • Operating System: macos, linux

Description

__post_deserialize__ hook causes deserialization errors with str or bool fields. Tested using DataClassDictMixin and Python versions 3.7-3.10.

What I Did

Narrowed down the simplest repro I could.

str example

@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'

bool example

@dataclass
class Data(DataClassDictMixin):
    foo: bool

    @classmethod
    def __post_deserialize__(cls, obj):
        return obj


print(Data.from_dict({'foo': True}))

result:

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'

int example

@dataclass
class Data(DataClassDictMixin):
    foo: int

    @classmethod
    def __post_deserialize__(cls, obj):
        return obj


print(Data.from_dict({'foo': 5}))

result:

Data(foo=5)

no hook

@dataclass
class Data(DataClassDictMixin):
    foo: bool


print(Data.from_dict({'foo': True}))

result:

Data(foo=True)
@Fatal1ty
Copy link
Owner

@cj-darius-lapunas

Thank you for finding the bug so quickly. I fixed it and will release 3.8.1 today.

@Fatal1ty
Copy link
Owner

Fixed in 3.8.1

@cj-darius-lapunas
Copy link
Author

Looks good on my end, thanks for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants