Skip to content

Commit

Permalink
Raise proper error when inputs are missing (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
1597463007 authored Dec 18, 2024
1 parent 77d6f7f commit 6ac880e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pargraph/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.0"
__version__ = "0.9.1"
10 changes: 7 additions & 3 deletions pargraph/graph/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/test_graph_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6ac880e

Please sign in to comment.