From 566015f446848be31f7b8d8c46cf10c4c11408f0 Mon Sep 17 00:00:00 2001 From: "Fabio M. Graetz, Ph.D" Date: Mon, 30 Oct 2023 19:04:01 +0100 Subject: [PATCH] Improve error message when omitting task kwarg in workflows (#1921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio Grätz Co-authored-by: Fabio Grätz --- flytekit/core/promise.py | 13 ++++++++++++- tests/flytekit/unit/core/test_references.py | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/flytekit/core/promise.py b/flytekit/core/promise.py index 5d598a017a..02c724e3a1 100644 --- a/flytekit/core/promise.py +++ b/flytekit/core/promise.py @@ -916,7 +916,18 @@ def create_and_link_node( ) is_optional = True if not is_optional: - raise _user_exceptions.FlyteAssertion("Input was not specified for: {} of type {}".format(k, var.type)) + from flytekit.core.base_task import Task + + error_msg = f"Input {k} of type {interface.inputs[k]} was not specified for function {entity.name}" + + _, _default = interface.inputs_with_defaults[k] + if isinstance(entity, Task) and _default is not None: + error_msg += ( + ". Flyte workflow syntax is a domain-specific language (DSL) for building execution graphs which " + "supports a subset of Python’s semantics. When calling tasks, all kwargs have to be provided." + ) + + raise _user_exceptions.FlyteAssertion(error_msg) else: continue v = kwargs[k] diff --git a/tests/flytekit/unit/core/test_references.py b/tests/flytekit/unit/core/test_references.py index 44cfbc7cf5..0e6fb9a70d 100644 --- a/tests/flytekit/unit/core/test_references.py +++ b/tests/flytekit/unit/core/test_references.py @@ -274,7 +274,7 @@ def test_lps(resource_type): with context_manager.FlyteContextManager.with_context(ctx.with_new_compilation_state()) as ctx: with pytest.raises(Exception) as e: ref_entity() - assert "Input was not specified" in f"{e}" + assert "was not specified for function" in f"{e}" output = ref_entity(a="hello", b=3) assert isinstance(output, VoidPromise) @@ -321,7 +321,7 @@ def test_ref_sub_wf(): with context_manager.FlyteContextManager.with_context(ctx.with_new_compilation_state()) as ctx: with pytest.raises(Exception) as e: ref_entity() - assert "Input was not specified" in f"{e}" + assert "was not specified for function" in f"{e}" output = ref_entity(a="hello", b=3) assert isinstance(output, VoidPromise)