Skip to content

Commit ea6843c

Browse files
jawwad-aliclaude
andauthored
fix(workflows): guard non-mapping 'inputs:' block in engine._resolve_inputs (#3696)
execute()/resume() run UNVALIDATED definitions (load_workflow does not validate). WorkflowDefinition stores `inputs` raw, so a non-mapping `inputs:` block (bare `inputs:` -> None, or `inputs: []`) crashed _resolve_inputs at `for name, input_def in definition.inputs.items()` with AttributeError, aborting the whole run. Return {} when inputs is not a mapping, mirroring validate_workflow's own `isinstance(definition.inputs, dict)` check. Protects both call sites (execute and resume); normal dict resolution is unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b0850c9 commit ea6843c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/specify_cli/workflows/engine.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,14 @@ def _resolve_inputs(
14001400
) -> dict[str, Any]:
14011401
"""Resolve workflow inputs against definitions and provided values."""
14021402
resolved: dict[str, Any] = {}
1403+
# execute()/resume() accept UNVALIDATED definitions (load_workflow does
1404+
# not validate). A non-mapping ``inputs:`` block (bare ``inputs:`` ->
1405+
# None, or ``inputs: []``) is stored raw, so iterating ``.items()`` here
1406+
# would crash the run with AttributeError. Treat a non-mapping inputs
1407+
# block as "no inputs"; validate_workflow reports the malformed shape
1408+
# via its own isinstance check.
1409+
if not isinstance(definition.inputs, dict):
1410+
return {}
14031411
for name, input_def in definition.inputs.items():
14041412
if not isinstance(input_def, dict):
14051413
continue

tests/test_workflows.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,23 @@ def test_from_string(self, sample_workflow_yaml):
36123612
assert definition.id == "test-workflow"
36133613
assert len(definition.inputs) == 2
36143614

3615+
@pytest.mark.parametrize(
3616+
"block",
3617+
[
3618+
"workflow:\n id: w\n name: W\nsteps: []\ninputs: []\n", # list
3619+
"workflow:\n id: w\n name: W\nsteps: []\ninputs:\n", # null
3620+
],
3621+
)
3622+
def test_resolve_inputs_tolerates_non_mapping_inputs(self, block):
3623+
# execute()/resume() run UNVALIDATED definitions; a non-mapping `inputs:`
3624+
# block (list/null) is stored raw and would crash _resolve_inputs at
3625+
# `.items()`. It must be treated as "no inputs" instead.
3626+
from specify_cli.workflows.engine import WorkflowDefinition, WorkflowEngine
3627+
3628+
definition = WorkflowDefinition.from_string(block)
3629+
resolved = WorkflowEngine()._resolve_inputs(definition, {}) # must not raise
3630+
assert resolved == {}
3631+
36153632
def test_from_string_invalid(self):
36163633
from specify_cli.workflows.engine import WorkflowDefinition
36173634

0 commit comments

Comments
 (0)