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

Fields from dataclasses that are Generic with unspecified TypeVars don't get serialized #66

Open
rhaps0dy opened this issue May 5, 2024 · 0 comments
Assignees
Labels
bug Something isn't working databind.core

Comments

@rhaps0dy
Copy link
Contributor

rhaps0dy commented May 5, 2024

Here's a minimal reproduction:

import dataclasses
from typing import Generic, TypeVar

import databind.json

T = TypeVar("T")


@dataclasses.dataclass
class A(Generic[T]):
    a_field: int


@dataclasses.dataclass
class B(A):
    b_field: str


b = B(2, "hi")
out = databind.json.get_object_mapper().serialize(b, B)

print(out)  # prints `{'b_field': 'hi'}`, which is wrong.

I've traced this to this line, which adds to the queue base in (hint.bases or hint.type.__bases__).

When T is uninstantiated, the former is non-empty, so the base dataclasses that come the normal way don't get added.

I don't fully understand this code but I think the fix is:

for base in (*hint.bases, *hint.type.__bases__)

to make sure we iterate over everything.

rhaps0dy added a commit to AlignmentResearch/train-learned-planner that referenced this issue May 5, 2024
@rhaps0dy rhaps0dy changed the title Fields fromdataclasses that are Generic with unspecified TypeVars don't get serialized Fields from dataclasses that are Generic with unspecified TypeVars don't get serialized May 5, 2024
@NiklasRosenstein NiklasRosenstein self-assigned this May 5, 2024
rhaps0dy added a commit to rhaps0dy/python-databind that referenced this issue May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working databind.core
Projects
None yet
Development

No branches or pull requests

2 participants