-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Type Mismatching while Serializing Dataclass with Union (#2859)
Signed-off-by: mao3267 <[email protected]> Signed-off-by: Katrina Rogan <[email protected]>
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters