Skip to content

Commit

Permalink
Failed to transform path string to Literal (#689)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
pingsutw authored and eapolinario committed Oct 8, 2021
1 parent fbbed40 commit abb12e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
17 changes: 8 additions & 9 deletions flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,15 @@ def dict_to_literal_map(
# to account for the type erasure that happens in the case of built-in collection containers, such as
# `list` and `dict`.
python_type = guessed_python_types.get(k, type(v))
if (hasattr(python_type, "__origin__") and not isinstance(v, python_type.__origin__)) or (
not hasattr(python_type, "__origin__") and not isinstance(v, python_type)
):
try:
literal_map[k] = TypeEngine.to_literal(
ctx=ctx,
python_val=v,
python_type=python_type,
expected=TypeEngine.to_literal_type(python_type),
)
except TypeError:
raise user_exceptions.FlyteTypeException(type(v), python_type, received_value=v)
literal_map[k] = TypeEngine.to_literal(
ctx=ctx,
python_val=v,
python_type=python_type,
expected=TypeEngine.to_literal_type(python_type),
)
return LiteralMap(literal_map)

@classmethod
Expand Down
19 changes: 19 additions & 0 deletions tests/flytekit/unit/core/test_type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from flytekit.models.literals import Blob, BlobMetadata, Literal, LiteralCollection, LiteralMap, Primitive, Scalar
from flytekit.models.types import LiteralType, SimpleType
from flytekit.types.directory.types import FlyteDirectory
from flytekit.types.file import JPEGImageFile
from flytekit.types.file.file import FlyteFile, FlyteFilePathTransformer


Expand Down Expand Up @@ -605,6 +606,24 @@ def test_enum_type():
}
),
),
(
{"p1": "s3://tmp/file.jpeg"},
{"p1": JPEGImageFile},
LiteralMap(
literals={
"p1": Literal(
scalar=Scalar(
blob=Blob(
metadata=BlobMetadata(
type=BlobType(format="jpeg", dimensionality=BlobType.BlobDimensionality.SINGLE)
),
uri="s3://tmp/file.jpeg",
)
)
)
}
),
),
],
)
def test_dict_to_literal_map(python_value, python_types, expected_literal_map):
Expand Down

0 comments on commit abb12e0

Please sign in to comment.