Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ability to pass None to task with Optional kwarg, add test #1657

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()