Repository navigation
Fix nested conditionals running skipped branches in local execution - #3473
Open
jackiectl2 wants to merge 1 commit into
Open
jackiectl2 wants to merge 1 commit into
jackiectl2 wants to merge 1 commit into
Conversation
In local execution, a conditional nested inside the active branch of another conditional (inline, or inside a subworkflow called from that branch) reused the parent's execution state, which was already marked BRANCH_ACTIVE. Every branch of the nested conditional therefore ran its tasks, even the ones whose condition was false. Give every local conditional section its own execution state starting in BRANCH_SKIPPED, so only the selected branch of a nested conditional runs. Sections nested in a skipped branch still become SkippedConditionalSection, as before. Closes flyteorg/flyte#6426 Signed-off-by: Tianlang (Jackie) Chen <305351710+jackiectl2@users.noreply.github.com>
jackiectl2
requested review from
cosmicbboy,
davidmirror-ops,
kumare3,
machichima,
pingsutw,
samhita-alla and
wild-endeavor
as code owners
October 10, 2026 00:28
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.
Tracking issue
Closes flyteorg/flyte#6426
Why are the changes needed?
In local execution, when a conditional is nested inside the active branch of another conditional (either inline in
.then(...)or inside a subworkflow called from that branch), every branch of the nested conditional executes its tasks, not only the selected one. In the issue's example,top_workflow(input_value=True)runsdo_test,do_nothing1anddo_nothing2, althoughdo_testreturnsFalseand onlydo_nothing2should run. The returned value is correct (the selected case's output is used), but the non-selected tasks still run, with their side effects and cost.The cause is
FlyteContext.Builder.enter_conditional_section: when already inside a condition whose branch isBRANCH_ACTIVE, it kept the parent's execution state object as-is. The nestedLocalExecutedConditionalSectiontherefore started inBRANCH_ACTIVE, and sincestart_branchonly ever sets the state to active, every branch ran.What changes were proposed in this pull request?
BRANCH_SKIPPED, exactly as a top-level conditional already did. The nested section then activates only its selected branch, and it no longer mutates the parent's state.conditional()still checks the parent's state and returns aSkippedConditionalSection.How was this patch tested?
Added two unit tests in
tests/flytekit/unit/core/test_conditions.pythat record which tasks actually execute:test_nested_condition_runs_only_selected_branch: inline nested conditional, checks the inner if / inner else / outer else paths.test_condition_in_subworkflow_called_from_branch: the reproduction from the issue (conditional inside a subworkflow called from a branch).Both fail on master and pass with this change. The other unit test modules that use conditionals (
test_dynamic_conditional,test_type_hints,test_workflows,test_serialization,test_gate,test_context_manager,test_promise,test_node_creation,test_references,remote/test_wrapper_classes) pass. Running all oftests/flytekit/unit/corelocally gave the same set of failures with and without this change (unrelated, environment-specific: docker / optional dependencies).Setup process
Screenshots
N/A
Check all the applicable boxes
Related PRs
None
Docs link
N/A