Open mao3267 opened 1 week ago
Here is another example I have come up with:
from dataclasses import dataclass
from flytekit import task
from typing import Union
@dataclass
class InnerDC:
ff: Union[None, int, str]
@dataclass
class DC:
inner_dc: InnerDC
@task
def t_dc() -> DC:
return DC(inner_dc=InnerDC(ff="string"))
Since Union
can contain multiple type candidates, I’m wondering if we should consider supporting this as well?
cc @Future-Outlier @wild-endeavor
Here is another example I have come up with:
from dataclasses import dataclass from flytekit import task from typing import Union @dataclass class InnerDC: ff: Union[None, int, str] @dataclass class DC: inner_dc: InnerDC @task def t_dc() -> DC: return DC(inner_dc=InnerDC(ff="string"))
Since
Union
can contain multiple type candidates, I’m wondering if we should consider supporting this as well? cc @Future-Outlier @wild-endeavor
YES DO IT
Describe the bug
Mentioned in the discussion under flyteorg/flytekit#2823. When handling Union types in
_make_dataset_serializable
, we intend to select the first argument inget_args(python_type)
becauseOptional
is equivalent toUnion[ExpectedType, None]
. However, this approach may fail if the type order differs, for example, inUnion[None, ExpectedType]
.An error reproduction example:
Expected behavior
This code snippet should work, meaning that the underlying Union types in dataclasses should be serialized correctly.
Additional context to reproduce
No response
Screenshots
No response
Are you sure this issue hasn't been raised already?
Have you read the Code of Conduct?