From 3d0a97e363eb8a6677d19db22b2c8d10b37f344f Mon Sep 17 00:00:00 2001 From: 1597463007 Date: Tue, 17 Dec 2024 11:39:44 -0500 Subject: [PATCH] Raise proper error when inputs are missing Signed-off-by: 1597463007 --- pargraph/about.py | 2 +- pargraph/graph/objects.py | 10 +++++++--- tests/test_graph_generation.py | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pargraph/about.py b/pargraph/about.py index 3e2f46a..d69d16e 100644 --- a/pargraph/about.py +++ b/pargraph/about.py @@ -1 +1 @@ -__version__ = "0.9.0" +__version__ = "0.9.1" diff --git a/pargraph/graph/objects.py b/pargraph/graph/objects.py index 49dacd0..121f040 100644 --- a/pargraph/graph/objects.py +++ b/pargraph/graph/objects.py @@ -843,9 +843,13 @@ def _convert_graph_to_dict( for input_key in self.inputs.keys(): graph_key = f"input_{input_key.key}_{uuid.uuid4().hex}" # if input key is not in inputs, use the default value - dict_graph[graph_key] = ( - inputs[input_key.key] if input_key.key in inputs else self.consts[self.inputs[input_key]].to_value() - ) + if input_key.key in inputs: + dict_graph[graph_key] = inputs[input_key.key] + elif self.inputs[input_key] is not None: + dict_graph[graph_key] = self.consts[self.inputs[input_key]].to_value() + else: + raise ValueError(f"input '{input_key.key}' not found in provided inputs") + key_to_uuid[input_key] = graph_key # assign random keys to all node paths and node output paths beforehand diff --git a/tests/test_graph_generation.py b/tests/test_graph_generation.py index d1c8614..6fe5617 100644 --- a/tests/test_graph_generation.py +++ b/tests/test_graph_generation.py @@ -317,3 +317,11 @@ def add(x: int, y: int = 1) -> int: return x + y self.assertEqual(self.engine.get(*add.to_graph().to_dict(x=2))[0], add(x=2)) + + def test_missing_input(self): + @graph + def add(x: int, y: int) -> int: + return x + y + + with self.assertRaises(ValueError): + add.to_graph().to_dict(x=2)