Skip to content

Commit

Permalink
Convert default dict to json string in pyflyte run (#1399)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>

Signed-off-by: Kevin Su <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
pingsutw and eapolinario committed Feb 22, 2023
1 parent 11d1fdf commit bfc2b15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions flytekit/clis/sdk_in_container/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ def convert_to_literal(
if self._literal_type.simple or self._literal_type.enum_type:
if self._literal_type.simple and self._literal_type.simple == SimpleType.STRUCT:
if self._python_type == dict:
if type(value) != str:
# The type of default value is dict, so we have to convert it to json string
value = json.dumps(value)
o = json.loads(value)
elif type(value) != self._python_type:
o = cast(DataClassJsonMixin, self._python_type).from_json(value)
Expand Down
6 changes: 4 additions & 2 deletions tests/flytekit/unit/cli/pyflyte/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ def print_all(
j: datetime.timedelta,
k: Color,
l: dict,
m: dict,
):
print(f"{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}")
print(f"{a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}, {m}")


@task
Expand Down Expand Up @@ -85,9 +86,10 @@ def my_wf(
l: dict,
remote: pd.DataFrame,
image: StructuredDataset,
m: dict = {"hello": "world"},
) -> Annotated[StructuredDataset, subset_cols]:
x = get_subset_df(df=remote) # noqa: shown for demonstration; users should use the same types between tasks
show_sd(in_sd=x)
show_sd(in_sd=image)
print_all(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h, i=i, j=j, k=k, l=l)
print_all(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h, i=i, j=j, k=k, l=l, m=m)
return x

0 comments on commit bfc2b15

Please sign in to comment.