Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise proper error when inputs are missing #22

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading