fix: Choice state applies default Assign/Output when rule shares same Next target#13775
Open
veeceey wants to merge 1 commit intolocalstack:mainfrom
Open
fix: Choice state applies default Assign/Output when rule shares same Next target#13775veeceey wants to merge 1 commit intolocalstack:mainfrom
veeceey wants to merge 1 commit intolocalstack:mainfrom
Conversation
… and default share same Next target When a Choice state rule and its Default both point to the same Next state, the default's Assign and Output were incorrectly applied even when a choice rule matched. This happened because `_eval_state_output` used the next state name to determine whether the default was selected, which is ambiguous when they share the same target. Fix by pushing a boolean flag onto the stack to explicitly track whether a choice rule matched vs the default path was taken. Fixes localstack#12301
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
localstack-bot
added a commit
that referenced
this pull request
Feb 15, 2026
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.
Problem
When a Choice state has a rule and a Default that both point to the same Next state (e.g., both go to "Pass"), the default's
AssignandOutputare incorrectly evaluated even when a choice rule actually matched.This happens because
_eval_state_outputdetermined whether the default was selected by comparingself.default_state.state_name == next_state_name-- which is ambiguous when a matched rule and the default target the same state.For example with this state machine:
{ "Type": "Choice", "Choices": [ { "Condition": "{% 'a' = 'a' and 'b' = 'b' %}", "Next": "Pass", "Assign": { "var_rule1": "rule 1" }, "Output": { "rule1": "from rule 1" } } ], "Default": "Pass", "Assign": { "var_DEFAULT": "from default" }, "Output": { "DEFAULT": "from default" } }The output would be
{"DEFAULT": "from default"}instead of{"rule1": "from rule 1"}, because the default's Output/Assign overwrote the matched rule's values.Fix
Instead of using next state name comparison (which breaks when they're the same), I push a boolean flag onto the environment stack to explicitly track whether a choice rule matched.
_eval_state_outputthen pops this flag to decide whether to apply the default's Assign/Output.Tests
Added test templates and test cases for both
AssignandOutputin Choice states where the matched rule and Default share the same Next target, with bothcondition=trueandcondition=falseinputs.Fixes #12301