Repository navigation
Conversation
The expression evaluator split a comparison at the first operator in _COMPARISON_OPERATORS table order and evaluated the whole remainder as the right operand, so a chained comparison such as `0 <= inputs.n <= 10` became `0 <= (inputs.n <= 10)` — a number compared against a boolean. Validation accepted the condition and nothing was raised at run time, so an `if`, `while` or `do-while` step silently took the wrong branch. Scan the expression left to right for every top-level comparison operator (longest operator first at each position, with the same quote/bracket skipping as _find_top_level) and evaluate the chain pairwise with an implicit `and`, the way Python and Jinja2 chain comparisons: `0 <= n <= 10` is `0 <= n and n <= 10`. Single comparisons keep their previous semantics, and every operand is evaluated before any pair is compared so validation probes visit the same leaves regardless of which pair fails first. Fixes github#5071 Assisted-by: Claude Code (model: Claude Fable 5, supervised)
This branch has not been deployed
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
Fixes #5071.
The workflow expression evaluator split a comparison at the first operator in
_COMPARISON_OPERATORStable order and evaluated the whole remainder as the right operand, so a chained comparison such as{{ 0 <= inputs.n <= 10 }}became0 <= (inputs.n <= 10)— a number compared against a boolean. Validation accepted the condition and nothing was raised at run time, so anif,whileordo-whilestep silently took the wrong branch (withn = 50the condition read true and thethenbranch ran).This PR makes the evaluator scan the expression left to right for every top-level comparison operator (longest operator first at each position, with the same quote/bracket skipping as
_find_top_level) and evaluate the chain pairwise with an implicitand, the way Python and Jinja2 chain comparisons:0 <= n <= 10is0 <= n and n <= 10. This matches the module's documented contract ("a safe Jinja2 subset").a < b == c,a < b in items.and/or, as before._collect_leaves) visit the same leaves regardless of which pair fails first.Testing
New regression test
TestExpressions::test_chained_comparisons_evaluate_like_pythonfails onmainexactly as the issue describes ({{ 0 <= inputs.n <= 10 }}isTrueforn = 50) and passes with this change. It also covers mixed-operator chains, chain-vs-and/orprecedence, and operator text inside quoted operands.The reproduction script from [Bug]: Chained comparisons such as
0 <= x <= 10in workflow expressions silently return the wrong result #5071 now prints the expected values,validate_workflowreports no errors, and theifstep runs theoutsidebranch forn = 50.tests/test_workflows.py+tests/workflows: all pass locally (.venv/bin/python -m pytestper CONTRIBUTING).Full suite: 13,649 passed; 11 failures in the script-parity tests (
test_*_python_parity.py) are a pre-existing local flake — the identical 11 fail on a cleanmaincheckout on the same machine, and each passes in isolation on both branches.Tested locally with
uv run specify --helpRan existing tests with
uv sync && uv run pytestTested with a sample project (if applicable)
AI Disclosure
AI disclosure: Written with Claude Code (model: Claude Fable 5, default reasoning effort, human-supervised). The agent located the defect, wrote the fix and the regression test, and ran the verification (failing-on-main test, issue repro script, full suite comparison against clean
main); I reviewed the diff and the evidence before submitting. The commit carries a matchingAssisted-by:trailer.🤖 Generated with Claude Code