Skip to content

Commit

Permalink
Failed to transform path string to Literal
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw committed Oct 7, 2021
1 parent 1fb425f commit ee615e8
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 @@ -28,6 +28,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 @@ -600,6 +601,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 ee615e8

Please sign in to comment.