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

Member variables of forward-referenced class types are ignored during serialization #70

Closed
seri114 opened this issue Feb 8, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@seri114
Copy link

seri114 commented Feb 8, 2022

Member variables of forward-referenced class types are ignored during serialization.

For example, consider the following case:

from __future__ import annotations
from dataclasses import dataclass
from mashumaro import DataClassDictMixin

@dataclass
class A(DataClassDictMixin):
    a:B

@dataclass
class B(DataClassDictMixin):
    b:int

a = A(B(1))
print(a.to_dict())

This gives us the expected:

{'a': {'b': 1}}

On the other hand, running the following case does not give the expected results.

@dataclass
class Base(DataClassDictMixin):
    pass

@dataclass
class A1(Base):
    a:B1

@dataclass
class B1(Base):
    b:int


a = A1(B1(1))
print(a.to_dict())

Result:

{}

At this time, no exception or error message will be generated.

Expected:

{'a': {'b': 1}}

Thanks for the excellent tool!

@Fatal1ty Fatal1ty added the bug Something isn't working label Feb 9, 2022
@Fatal1ty
Copy link
Owner

Fatal1ty commented Feb 9, 2022

Hi @seri114

Thank you for spotting this! It is fixed in this branch. The next release will be very soon.

@Fatal1ty
Copy link
Owner

Fatal1ty commented Feb 9, 2022

It it's fixed in 3.0.

@Fatal1ty Fatal1ty closed this as completed Feb 9, 2022
@seri114
Copy link
Author

seri114 commented Feb 9, 2022

I have confirmed that this has been fixed in the v3.0 release.
Thanks again!
@Fatal1ty

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

No branches or pull requests

2 participants