Skip to content

Commit

Permalink
Remove hard failure if missing inputs (#7116)
Browse files Browse the repository at this point in the history
* Remove hard failure if missing inputs

* Fix imports

* formatting

* Lint
  • Loading branch information
dpeng817 committed Mar 17, 2022
1 parent 1c7f030 commit 24290ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,6 @@ def _resolve_inputs(
for k, v in unassigned_kwargs.items():
input_dict[k] = v

# Error if any inputs are not represented in input_dict
input_def_names = set(input_defs_by_name.keys())
provided_input_names = set(input_dict.keys())

missing_inputs = input_def_names - provided_input_names
extra_inputs = provided_input_names - input_def_names

if missing_inputs or extra_inputs:
error_msg = ""
if extra_inputs:
error_msg += f"Invocation had extra inputs {list(extra_inputs)}."
if missing_inputs:
error_msg += f"Invocation had missing inputs {list(missing_inputs)}."
raise DagsterInvalidInvocationError(error_msg)

# Type check inputs
op_label = context.describe_op()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import re
from functools import partial

import pytest

Expand Down Expand Up @@ -1035,14 +1036,30 @@ def the_op(**kwargs) -> str:

assert the_op(the_in="bar") == "barfoo"

with pytest.raises(
DagsterInvalidInvocationError,
match="Invocation had extra inputs \['bad_val'\].Invocation had missing inputs \['the_in'\].",
):
with pytest.raises(KeyError):
the_op(bad_val="bar")

@op(ins={"the_in": In(), "kwarg_in": In(), "kwarg_in_two": In()})
def the_op(the_in, **kwargs):
return the_in + kwargs["kwarg_in"] + kwargs["kwarg_in_two"]

assert the_op("foo", kwarg_in="bar", kwarg_in_two="baz") == "foobarbaz"


def test_default_kwarg_inputs():
@op
def the_op(x=1, y=2):
return x + y

assert the_op() == 3


def test_kwargs_via_partial_functools():
def fake_func(foo, bar):
return foo + bar

new_func = partial(fake_func, foo=1, bar=2)

new_op = op(name="new_func")(new_func)

assert new_op() == 3

0 comments on commit 24290ad

Please sign in to comment.