-
Notifications
You must be signed in to change notification settings - Fork 305
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
Type Mismatching while Serializing Dataclass with Union #2859
Changes from all commits
96c0e5c
f647bd3
a7ea0e9
dff0829
b9a4051
c4c3ce7
4894ae5
1fdf3d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from dataclasses import dataclass | ||
from flytekit.types.file import FlyteFile | ||
from flytekit.types.structured.structured_dataset import StructuredDataset | ||
from flytekit.core.type_engine import DataclassTransformer | ||
from typing import Union | ||
import pytest | ||
import re | ||
|
||
def test_dataclass_union_with_multiple_flytetypes_error(): | ||
@dataclass | ||
class DC(): | ||
x: Union[None, StructuredDataset, FlyteFile] | ||
|
||
|
||
dc = DC(x="s3://my-bucket/my-file") | ||
with pytest.raises(ValueError, match=re.escape("Cannot have more than one Flyte type in the Union when attempting to use the string shortcut. Please specify the full object (e.g. FlyteFile(...)) instead of just passing a string.")): | ||
DataclassTransformer()._make_dataclass_serializable(dc, DC) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,7 @@ class TestFileStruct(DataClassJsonMixin): | |
b: typing.Optional[FlyteFile] | ||
b_prime: typing.Optional[FlyteFile] | ||
c: typing.Union[FlyteFile, None] | ||
c_prime: typing.Union[None, FlyteFile] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although we didn’t expect |
||
d: typing.List[FlyteFile] | ||
e: typing.List[typing.Optional[FlyteFile]] | ||
e_prime: typing.List[typing.Optional[FlyteFile]] | ||
|
@@ -989,6 +990,7 @@ class TestFileStruct(DataClassJsonMixin): | |
b=f1, | ||
b_prime=None, | ||
c=f1, | ||
c_prime=f1, | ||
d=[f1], | ||
e=[f1], | ||
e_prime=[None], | ||
|
@@ -1011,6 +1013,7 @@ class TestFileStruct(DataClassJsonMixin): | |
assert dict_obj["b"]["path"] == remote_path | ||
assert dict_obj["b_prime"] is None | ||
assert dict_obj["c"]["path"] == remote_path | ||
assert dict_obj["c_prime"]["path"] == remote_path | ||
assert dict_obj["d"][0]["path"] == remote_path | ||
assert dict_obj["e"][0]["path"] == remote_path | ||
assert dict_obj["e_prime"][0] is None | ||
|
@@ -1028,6 +1031,7 @@ class TestFileStruct(DataClassJsonMixin): | |
assert o.b.remote_path == ot.b.remote_source | ||
assert ot.b_prime is None | ||
assert o.c.remote_path == ot.c.remote_source | ||
assert o.c_prime.remote_path == ot.c_prime.remote_source | ||
assert o.d[0].remote_path == ot.d[0].remote_source | ||
assert o.e[0].remote_path == ot.e[0].remote_source | ||
assert o.e_prime == [None] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually can you write one more unit test for me please? (and add it under
test_dataclass.py
this file is getting too big).then call
_make_dataclass_serializable
onUnion[None, A, B]
whereb = B(x="s3://tmp)
or something.