Skip to content

Commit

Permalink
Fix ability to pass None to task with Optional kwarg, add test (#1657)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Grätz <[email protected]>
Co-authored-by: Fabio Grätz <[email protected]>
  • Loading branch information
fg91 and Fabio Grätz authored May 26, 2023
1 parent eafcc82 commit f671fb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flytekit/core/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def binding_data_from_python_std(
f"Cannot pass output from task {t_value.task_name} that produces no outputs to a downstream task"
)

elif expected_literal_type.union_type is not None:
elif t_value is not None and expected_literal_type.union_type is not None:
for i in range(len(expected_literal_type.union_type.variants)):
try:
lt_type = expected_literal_type.union_type.variants[i]
Expand Down
15 changes: 15 additions & 0 deletions tests/flytekit/unit/core/test_promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,18 @@ def t1(a: typing.Union[float, typing.Dict[str, int]]):
t1.interface.inputs,
t1.python_interface.inputs,
)


def test_optional_task_kwargs():
from typing import Optional

from flytekit import Workflow

@task
def func(foo: Optional[int] = None):
pass

wf = Workflow(name="test")
wf.add_entity(func, foo=None)

wf()

0 comments on commit f671fb6

Please sign in to comment.