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

Fix python client model class hydration issue #1221

Merged
merged 8 commits into from
Nov 6, 2024

Conversation

shangyian
Copy link
Contributor

@shangyian shangyian commented Nov 6, 2024

Summary

This fixes an issue where the python client's model classes weren't hydrating as dataclasses, but as dictionaries. For example, the expected type of type(col) here should be Column:

source_node = dj.source("source.node")
[type(col) for col in source_node.columns]

This fixes things by adding a custom serializer from dictionaries to DJ model dataclasses: SerializableMixin. This mixin includes a from_dict method that will examine the structure of the dataclass and recursively convert a dictionary to the dataclass.

Test Plan

Deployment Plan

N/A

@shangyian shangyian added the bug Something isn't working label Nov 6, 2024
Copy link

netlify bot commented Nov 6, 2024

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 62a9068
🔍 Latest deploy log https://app.netlify.com/sites/thriving-cassata-78ae72/deploys/672bb33e1fc0bd000840976d

@shangyian shangyian marked this pull request as ready for review November 6, 2024 17:40
@shangyian shangyian changed the title Client dataclass Fix python client model class hydration issue Nov 6, 2024
Copy link
Member

@agorajek agorajek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick fix!

T = TypeVar("T")


class SerializableMixin: # pylint: disable=too-few-public-methods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be part of _internal module, but no big deal either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I originally had it there but it felt like that file got really long. This piece is pretty generic whereas that module is now mostly client models.

@shangyian shangyian merged commit 510b1b7 into DataJunction:main Nov 6, 2024
16 checks passed
@shangyian shangyian deleted the client-dataclass branch November 6, 2024 20:01
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 this pull request may close these issues.

2 participants