Skip to content

Commit 41dc037

Browse files
committed
Restrict input values
To a subset of JSONifiable types Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
1 parent b354427 commit 41dc037

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/python_workflow_definition/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
)
2020

2121

22+
JsonPrimitive = Union[str, int, float, bool, None]
23+
24+
2225
class PythonWorkflowDefinitionBaseNode(BaseModel):
2326
"""Base model for all node types, containing common fields."""
2427

@@ -33,7 +36,7 @@ class PythonWorkflowDefinitionInputNode(PythonWorkflowDefinitionBaseNode):
3336

3437
type: Literal["input"]
3538
name: str
36-
value: Optional[Any] = None
39+
value: Optional[JsonPrimitive] = None
3740

3841

3942
class PythonWorkflowDefinitionOutputNode(PythonWorkflowDefinitionBaseNode):

tests/test_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest import mock
55
from pydantic import ValidationError
66
from python_workflow_definition.models import (
7+
JsonPrimitive,
78
PythonWorkflowDefinitionInputNode,
89
PythonWorkflowDefinitionOutputNode,
910
PythonWorkflowDefinitionFunctionNode,
@@ -40,6 +41,19 @@ def test_input_node(self):
4041
)
4142
self.assertEqual(node_with_value.value, 42)
4243

44+
def test_input_node_invalid_value_raises(self):
45+
bad_value = (1, 2)
46+
self.assertNotIsInstance(bad_value, JsonPrimitive)
47+
with self.assertRaises(ValidationError):
48+
PythonWorkflowDefinitionInputNode.model_validate(
49+
{
50+
"id": 0,
51+
"type": "input",
52+
"name": "x",
53+
"value": bad_value,
54+
}
55+
)
56+
4357
def test_output_node(self):
4458
node = PythonWorkflowDefinitionOutputNode(id=1, type="output", name="test_output")
4559
self.assertEqual(node.id, 1)

0 commit comments

Comments
 (0)