fix(workflows): fail if/switch steps on non-list branch instead of crashing#3515
Open
Noor-ul-ain001 wants to merge 2 commits into
Open
fix(workflows): fail if/switch steps on non-list branch instead of crashing#3515Noor-ul-ain001 wants to merge 2 commits into
Noor-ul-ain001 wants to merge 2 commits into
Conversation
…ashing `IfThenStep.validate()` and `SwitchStep.validate()` already reject a non-list branch (`then`/`else`, and `case`/`default`), but the engine's `execute()` path does not auto-validate (see `WorkflowEngine.load_workflow`, whose docstring notes the definition is "not yet validated"). On an unvalidated run, the selected branch is fed straight into `next_steps`, which `_execute_steps` iterates as step mappings. A non-list branch — a single mapping or scalar authoring mistake — was iterated element-wise (a dict yields its string keys, a str its characters) and raised `AttributeError` on `.get()`, taking down the whole run; the engine invokes `step_impl.execute()` with no surrounding try/except. Guard both `execute` paths to return a FAILED StepResult naming the type error instead, mirroring the switch non-mapping `cases` and fan-out non-list `items` handling. The switch guard is factored into a shared `_non_list_branch_failure` helper covering both `case` and `default` branches. A missing `else`/`default` still defaults to an empty list (COMPLETED), unchanged; the guard fires only on an explicit non-list value. The condition/expression is still evaluated first, so its result is surfaced in the step output for downstream context. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds runtime validation for malformed conditional workflow branches to fail steps cleanly instead of crashing execution.
Changes:
- Guards non-list
ifbranches. - Guards non-list switch case/default branches.
- Adds malformed
then/elsetests.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/steps/if_then/__init__.py |
Validates selected branch types during execution. |
src/specify_cli/workflows/steps/switch/__init__.py |
Validates selected case and default branch types. |
tests/test_workflows.py |
Tests malformed if-branch execution. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Medium
| # ``.get()``. ``validate`` already rejects a non-list branch; fail this | ||
| # step loudly on an unvalidated run instead, mirroring the switch/fan-out | ||
| # steps. A missing ``else`` defaults to ``[]`` and stays valid. | ||
| if not isinstance(branch, list): |
| ) | ||
| for case_key, case_steps in cases.items(): | ||
| if str(case_key) == str_value: | ||
| if not isinstance(case_steps, list): |
mnriem
requested changes
Jul 14, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Summary
IfThenStep.validate()andSwitchStep.validate()already reject a non-list branch (then/else, andcase/default), but the engine'sexecute()path does not auto-validate — seeWorkflowEngine.load_workflow, whose docstring notes the definition is "not yet validated". On an unvalidated run the selected branch is fed straight intonext_steps, which_execute_stepsiterates as step mappings. A non-list branch (a single mapping or scalar authoring mistake) was iterated element-wise — a dict yields its string keys, a str its characters — and raisedAttributeErroron.get(), taking down the whole run; the engine invokesstep_impl.execute()with no surrounding try/except.This guards both
executepaths to return a FAILEDStepResultnaming the type error instead, mirroring the switch non-mappingcasesguard (#3481) and the fan-out non-listitemshandling.Changes
if_then— guard boththenandelsebranches at execute time.switch— guardcaseanddefaultbranches via a shared_non_list_branch_failurehelper.else/defaultstill defaults to an empty list (COMPLETED), unchanged; the guard fires only on an explicit non-list value.Tests
Added parametrized tests for non-list
thenandelse(dict / str / int). Full workflow logic suite passes locally.Follows the same pattern as #3481 (switch non-mapping cases) and #3482 (fan-in non-list wait_for).