Fix: Skip expansion of mapped task group when list is empty (2.5.1+affirm4)#34
Merged
alanxu00 merged 2 commits intoJun 16, 2026
Merged
Conversation
Move ti_count zero/None check before division to prevent ZeroDivisionError in _get_relevant_upstream_map_indexes when a mapped task group is expanded with an empty list, which caused the scheduler to enter a crash loop. Ports upstream fix; adds regression test covering empty-list expansion with downstream task referencing the group via XCom pull.
alanxu00
approved these changes
Jun 16, 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.
Summary
Ports upstream fix apache/airflow#30084 to our 2.5.1 fork, and bumps the fork version to
2.5.1+affirm4.Problem
Expanding a mapped task group fails when the input list is empty and a downstream task references a mapped index via XCom pull of that group. In that case, the entire task group should be skipped — instead, the scheduler enters a crash loop.
Root cause: in
TaskInstance.get_relevant_upstream_map_indexes,ancestor_map_indexis calculated asself.map_index * ancestor_ti_count // ti_count. When a task group is expanded with an empty list,ti_countis0, causing aZeroDivisionError.Fix
Move the early-return guard before the division and broaden it from
if ti_count is Nonetoif not ti_count, so bothNoneand0short-circuit to returningNone(which callers already treat as "no partial mapping — use the whole value / all upstreams").Changes
airflow/models/taskinstance.py— reorder and broaden theti_countguard inget_relevant_upstream_map_indexes.tests/ti_deps/deps/test_trigger_rule_dep.py— addtest_upstream_in_mapped_group_when_mapped_tasks_list_is_emptyregression test.setup.py— bump fork version2.5.1+affirm3→2.5.1+affirm4.Compatibility
Signature of
get_relevant_upstream_map_indexesis unchanged. Both call sites (airflow/models/xcom_arg.pyandairflow/ti_deps/deps/trigger_rule_dep.py) already handle aNonereturn.Test plan
test_upstream_in_mapped_group_when_mapped_tasks_list_is_emptypasses.