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

[wip] Fix Union Type Dataclass Ambiguous Error #2646

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,16 @@ def get_literal_type(self, t: Type[T]) -> LiteralType:
)
)

ts = TypeStructure(tag="", dataclass_type=literal_type)
ts = TypeStructure(tag=f"{t.__module__}.{t.__qualname__}", dataclass_type=literal_type)

return _type_models.LiteralType(simple=_type_models.SimpleType.STRUCT, metadata=schema, structure=ts)

def to_literal(self, ctx: FlyteContext, python_val: T, python_type: Type[T], expected: LiteralType) -> Literal:
metadata = {"dataclass_path": f"{python_type.__module__}.{python_type.__qualname__}"}

if isinstance(python_val, dict):
json_str = json.dumps(python_val)
return Literal(scalar=Scalar(generic=_json_format.Parse(json_str, _struct.Struct())))
return Literal(scalar=Scalar(generic=_json_format.Parse(json_str, _struct.Struct())), metadata=metadata)

if not dataclasses.is_dataclass(python_val):
raise TypeTransformerFailedError(
Expand All @@ -519,7 +521,7 @@ def to_literal(self, ctx: FlyteContext, python_val: T, python_type: Type[T], exp
f" and implement _serialize and _deserialize methods."
)

return Literal(scalar=Scalar(generic=_json_format.Parse(json_str, _struct.Struct()))) # type: ignore
return Literal(scalar=Scalar(generic=_json_format.Parse(json_str, _struct.Struct())), metadata=metadata) # type: ignore

def _get_origin_type_in_annotation(self, python_type: Type[T]) -> Type[T]:
# dataclass will try to hash python type when calling dataclass.schema(), but some types in the annotation is
Expand Down
Loading