fix(workflows): reject bool max_iterations in while/do-while validation#3237
Open
jawwad-ali wants to merge 1 commit into
Open
fix(workflows): reject bool max_iterations in while/do-while validation#3237jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
while/do-while validate() checked 'not isinstance(max_iter, int) or max_iter < 1'. Since bool is a subclass of int, isinstance(True, int) is True and True < 1 is False, so 'max_iterations: true' passed validation and then ran as a single iteration (range(True) == range(1)) instead of being reported as a type error. Reject bools explicitly, matching the fail-fast-on-bool handling already used for number inputs and gate options. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a validation hole in workflow loop steps where max_iterations: true could pass type checks (because bool is an int subclass in Python) and be silently treated as a single iteration, instead of being rejected as an invalid configuration.
Changes:
- Update
WhileStep.validate()andDoWhileStep.validate()to explicitly reject boolean values formax_iterations. - Extend workflow tests to cover
max_iterations=Truerejection for both while and do-while steps.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/steps/while_loop/__init__.py |
Explicitly rejects boolean max_iterations during while-step validation to avoid silent single-iteration behavior. |
src/specify_cli/workflows/steps/do_while/__init__.py |
Mirrors the while-step fix for do-while validation by explicitly rejecting boolean max_iterations. |
tests/test_workflows.py |
Adds/extends regression tests ensuring max_iterations=True is rejected and valid integers are still accepted. |
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: 1
- Review effort level: Low
Comment on lines
+1842
to
+1845
| ok = step.validate( | ||
| {"id": "test", "condition": "{{ true }}", "max_iterations": 3, "steps": []} | ||
| ) | ||
| assert not any("max_iterations" in e for e in ok) |
Collaborator
|
Please address Copilot feedback |
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.
Description
WhileStep.validate()andDoWhileStep.validate()check:Since
boolis a subclass ofint,isinstance(True, int)isTrueandTrue < 1isFalse— somax_iterations: truepasses validation. It is then used as a loop bound, andrange(True) == range(1), so the loop silently runs one iteration instead of the author's intent being flagged as a type error.This is the same bool-is-int trap already guarded against for number inputs (
_coerce_input, #3199) and gate options.Fix
Reject bools explicitly in both
whileanddo-whilevalidators.Testing
uvx ruff checkclean;TestWhileStep+TestDoWhileSteppass (10 tests).test_validate_invalid_max_iterations(while) and addedtest_validate_rejects_bool_max_iterations(do-while):max_iterations: truenow returns the "must be an integer >= 1" error; a real positive integer is still accepted. Fails before, passes after.AI Disclosure
Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI identified the bool-is-int trap shared by both loop validators (consistent with the existing number/gate guards); I confirmed the silent single-iteration behavior and the fix on both real validators, and reviewed the diff before submitting.