From b434ddf40e1b84bba56e8f6e27a6602a86c7d656 Mon Sep 17 00:00:00 2001 From: Chi-Sheng Liu Date: Fri, 10 May 2024 01:51:06 +0800 Subject: [PATCH] feat(bindings): Task arguments default value binding Resolves: flyteorg/flyte#5321 Signed-off-by: Chi-Sheng Liu --- flytekit/core/promise.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flytekit/core/promise.py b/flytekit/core/promise.py index aa4e5f3150a..e8aa17c0be1 100644 --- a/flytekit/core/promise.py +++ b/flytekit/core/promise.py @@ -1053,7 +1053,7 @@ def create_and_link_node( for k in sorted(interface.inputs): var = typed_interface.inputs[k] - if k not in kwargs: + if k not in kwargs and k not in interface.inputs_with_defaults: is_optional = False if var.type.union_type: for variant in var.type.union_type.variants: @@ -1079,7 +1079,7 @@ def create_and_link_node( raise _user_exceptions.FlyteAssertion(error_msg) else: continue - v = kwargs[k] + v = kwargs.get(k) or interface.inputs_with_defaults.get(k)[1] # This check ensures that tuples are not passed into a function, as tuples are not supported by Flyte # Usually a Tuple will indicate that multiple outputs from a previous task were accidentally passed # into the function. @@ -1102,7 +1102,7 @@ def create_and_link_node( except Exception as e: raise AssertionError(f"Failed to Bind variable {k} for function {entity.name}.") from e - extra_inputs = used_inputs ^ set(kwargs.keys()) + extra_inputs = used_inputs ^ (set(kwargs.keys()) | set(interface.inputs_with_defaults)) if len(extra_inputs) > 0: raise _user_exceptions.FlyteAssertion( "Too many inputs were specified for the interface. Extra inputs were: {}".format(extra_inputs)