ShousenZHANG opened a new pull request, #73729:
URL: https://github.com/apache/airflow/pull/73729

   Clearing a task instance for a specific Dag run with both `include_upstream` 
and `include_downstream` also selected tasks that are neither upstream nor 
downstream of the selected one. In a Dag whose branches share a root, it 
selected the whole run (#73710).
   
   `post_clear_task_instances` collects relatives through the nested 
`_collect_relatives`, which passed `normal_task_ids` / `mapped_tasks_tuples` to 
`find_relevant_relatives` and then added the results back into those same sets. 
With both flags set the upstream pass runs first, so the downstream pass 
started from the selected tasks *and* their ancestors, and returned every 
descendant of those ancestors.
   
   This PR takes a snapshot of the selected tasks before either pass and gives 
both passes that snapshot, so each direction is computed from what the caller 
asked for and the results are unioned. That is also what the `dag_run_id is 
None` branch of the same function already gets from 
`dag.partial_subset(include_upstream=..., include_downstream=...)`. Mapped 
tasks (`(task_id, map_index)` tuples) go through the same snapshot. 
Single-direction clears were already correct and are unchanged.
   
   The regression test builds the Dag from the report (`root >> a >> b`, `root 
>> other`) and dry-runs a clear of `a` with each flag combination. With both 
flags, `main` returns `a, b, other, root`; with this change it returns `a, b, 
root`. The upstream-only and downstream-only cases are in the same 
parametrization and pass either way.
   
   Tested locally:
   
   - the new test: 3 passed; with the source change reverted, the both-flags 
case fails
   - `test_task_instances.py`: 349 passed
   - prek on the changed files: all hooks pass except `generate-openapi-spec`, 
which needs the CI image; I ran its script directly instead and the generated 
spec is unchanged, as expected for a change inside the handler body
   
   closes: #73710
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: Claude Code following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to