Skip to content

fix: Choice state applies default Assign/Output when rule shares same Next target#13775

Open
veeceey wants to merge 1 commit intolocalstack:mainfrom
veeceey:fix/issue-12301-choice-state-default-override
Open

fix: Choice state applies default Assign/Output when rule shares same Next target#13775
veeceey wants to merge 1 commit intolocalstack:mainfrom
veeceey:fix/issue-12301-choice-state-default-override

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 14, 2026

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 Assign and Output are incorrectly evaluated even when a choice rule actually matched.

This happens because _eval_state_output determined whether the default was selected by comparing self.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_output then pops this flag to decide whether to apply the default's Assign/Output.

Tests

Added test templates and test cases for both Assign and Output in Choice states where the matched rule and Default share the same Next target, with both condition=true and condition=false inputs.

Fixes #12301

… 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
@localstack-bot
Copy link
Contributor

localstack-bot commented Feb 14, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@veeceey
Copy link
Author

veeceey commented Feb 15, 2026

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: StepFunctions: Choice state: Default choice is executed even though another choice rule is evaluated to true

2 participants