Repository navigation
Fix clearing with upstream and downstream selecting unrelated tasks - #74548
Open
sjyangkevin wants to merge 1 commit into
Open
sjyangkevin wants to merge 1 commit into
sjyangkevin wants to merge 1 commit into
Conversation
sjyangkevin
marked this pull request as ready for review
October 10, 2026 21:35
sjyangkevin
requested review from
bugraoz93,
choo121600,
ephraimbuddy,
henry3260,
jason810496,
pierrejeambrun,
rawwar and
shubhamraj-git
as code owners
October 10, 2026 21:35
Clearing a task in a specific Dag run with both upstream and downstream enabled resolved the downstream relatives from the selected tasks plus their upstream tasks, so every other descendant of those upstream tasks was selected too. In a Dag whose branches share a root task this cleared the whole run, and selecting one map index of a mapped task cleared all of its map indexes. Each direction has to be resolved from the requested tasks alone, as clearing without a specific Dag run already does.
sjyangkevin
force-pushed
the
fix-clear-upstream-downstream-unrelated-tasks
branch
from
October 10, 2026 23:53
83cb4a8 to
3b9a97b
Compare
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.
Why
closes: #73710
Clearing a task instance in a specific Dag run with both Upstream and Downstream enabled (the Clear dialog toggles, or
POST /api/v2/dags/{dag_id}/clearTaskInstanceswith adag_run_id) also selected tasks that are neither upstream nor downstream of the selected task.For a specific Dag run,
post_clear_task_instancesresolves relatives one direction at a time withfind_relevant_relatives, and each pass added its results to the selection immediately. The upstream pass ran first and grew the selection, so the downstream pass started from the selected task and its upstream tasks, and returned every descendant of those upstream tasks.With the Dag from the issue (
root >> a >> b,root >> other), clearingawith both options:main{a}→root{a, root}→a, b, othera, b, other, root{a}→root{a}→ba, b, rootAs a result:
a[0]) also selected every map index ofa, because the downstream pass fromrootreturnedaas a whole task, which replaces the specific map index.Clearing with only Upstream or only Downstream was not affected.
Approach
Both passes now start from the tasks in the request, and their results are merged into the selection only after both have run. This gives the same result as clearing without a
dag_run_id(partial_subset(include_upstream=..., include_downstream=...)) and as marking a task success/failed with upstream and downstream.find_relevant_relativesitself is unchanged.Why this does not introduce a regression
find_relevant_relativescall with the same, unmodified input; only the place where its result is merged moved.selected ∪ up(selected) ∪ down(selected ∪ up(selected)). After:selected ∪ up(selected) ∪ down(selected). The tasks dropped are exactly descendants of upstream tasks that are not relatives of the selected task.get_upstreams_follow_setups), and the downstream pass adds the setups/teardowns of downstream tasks (partial_subset). Map index resolution infind_relevant_relativesis untouched.dag_run_idand the UI code are unchanged.Testing
Unit tests
test_clear_with_upstream_and_downstream_excludes_unrelated_tasks, parametrized for an unmapped selection (a) and a mapped one (a[0]). Onmainboth fail (extraother; extraa[1],a[2]andother); with this change both pass.breeze verifyin Breeze (Python 3.11, SQLite), one suite at a time:APIDB tests: 3743 passed, 10 skippedAlwaysDB tests: 1891 passed, 3 skippedfabprovider: 407 DB and 296 non-DB tests passed, 5 skippedcommon.compatprovider: 283 passed, 11 skippedairflow-core,devel-common) and OpenAPI spec generation (spec unchanged).Manual testing in Breeze (
breeze start-airflow --dev-mode), Clear dialog with Upstream + Downstream enabled (screenshots below):root >> a >> b,root >> other), clearinga: selectsa, b, root.startfanning out to threeextract >> transform >> loadpipelines, clearingtransform_sales: selects only the foursales-pipeline tasks (start,extract_sales,transform_sales,load_sales) instead of the whole run.amapped over 3 inputs, clearinga[0]: selectsa[0], b, root.The same three Dags were also checked through the REST API (dry run) against a running API server: with both options the results match the above, and Upstream-only and Downstream-only results are identical to
main.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.