fix(workflows): if step execute() fails cleanly on a non-list branch#3528
Open
jawwad-ali wants to merge 2 commits into
Open
fix(workflows): if step execute() fails cleanly on a non-list branch#3528jawwad-ali wants to merge 2 commits into
jawwad-ali wants to merge 2 commits into
Conversation
jawwad-ali
force-pushed
the
fix/control-flow-nonlist-branch-guard
branch
from
July 15, 2026 05:28
9ef71fa to
c89db54
Compare
Contributor
Author
Contributor
There was a problem hiding this comment.
Pull request overview
Adds runtime validation so malformed if branches fail cleanly instead of crashing workflow execution.
Changes:
- Rejects selected non-list
then/elsebranches. - Adds parameterized tests for strings, mappings, and integers.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/steps/if_then/__init__.py |
Adds branch type validation. |
tests/test_workflows.py |
Tests malformed branch handling. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
IfThenStep.execute returns config['then']/['else'] directly as StepResult.next_steps with no check that it is a list. The engine does not auto-validate step config before execute(), so an unvalidated run with a non-list branch (a scalar or mapping authoring mistake) passes a non-iterable as next_steps and crashes the whole run. validate() catches this, but execute() should fail the step loudly instead. Add an isinstance(list) guard returning a FAILED StepResult, completing the same guard github#3519 added to the while/do-while steps (and that its comment already references for the 'if' step) and mirroring the switch step's 'cases' guard. Parametrized test feeds a str/dict/int branch and asserts FAILED (fails before: the non-iterable next_steps crashed execution). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The non-list guard turned a valid 'else: null' into a FAILED result on a false condition — but validate() deliberately accepts None as 'no else branch' (test_validate_accepts_valid_else). Normalize a selected None branch to [] before the guard so validation and execution stay consistent; the guard still rejects genuine non-list values (str/dict/int). Test: false condition + else: null now COMPLETES with no next steps (fails before: FAILED 'else must be a list ... NoneType'). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jawwad-ali
force-pushed
the
fix/control-flow-nonlist-branch-guard
branch
from
July 17, 2026 10:29
c89db54 to
5f90f89
Compare
Comment on lines
+34
to
+35
| if branch is None: | ||
| branch = [] |
Comment on lines
+37
to
+55
| if not isinstance(branch, list): | ||
| # The engine does not auto-validate step config and feeds | ||
| # ``next_steps`` straight into ``_execute_steps``, which iterates them | ||
| # as step mappings. A non-list ``then``/``else`` (a single mapping or | ||
| # scalar authoring mistake) would otherwise be iterated element-wise | ||
| # — a dict yields its keys, a str its characters — and crash the whole | ||
| # run with AttributeError on ``.get()``. ``validate`` already rejects | ||
| # a non-list branch; fail this step loudly on an unvalidated run | ||
| # instead, mirroring the while/do-while (#3519) / switch / fan-out | ||
| # steps. The selected branch is always returned as next_steps, so the | ||
| # guard is unconditional. | ||
| return StepResult( | ||
| status=StepStatus.FAILED, | ||
| error=( | ||
| f"If step {config.get('id', '?')!r}: {branch_name!r} must be a " | ||
| f"list of steps, got {type(branch).__name__}." | ||
| ), | ||
| output={"condition_result": result}, | ||
| ) |
mnriem
requested changes
Jul 17, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback. If not applicable, please explain why
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
IfThenStep.executereturnsconfig['then']/['else']directly asStepResult.next_stepswith no check that it's a list:The engine does not auto-validate step config before
execute(), so an unvalidated run with a non-list branch (a scalar or mapping authoring mistake) passes a non-iterable asnext_stepsand crashes the whole run.validate()catches this, butexecute()should fail the step loudly rather than take down the run.Fix
Add an
isinstance(..., list)guard returning aFAILEDStepResult. This completes the same guard #3519 added to thewhile/do-whilesteps — whose comment already references theifstep as a peer — and mirrors theswitchstep'scasesguard.Test
Parametrized
test_execute_rejects_non_list_branchfeeds astr/dict/intbranch and assertsFAILED— fails before (the non-iterablenext_stepscrashed execution), passes after.🤖 Written with the assistance of Claude Code (AI). Bug self-found; fix/tests verified locally (fail-before / pass-after), ruff clean.