sjyangkevin commented on code in PR #74548:
URL: https://github.com/apache/airflow/pull/74548#discussion_r4241954784


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/task_instances.py:
##########
@@ -1119,10 +1119,15 @@ def _collect_relatives(run_id: str, direction: 
Literal["upstream", "downstream"]
                 )
                 normal_task_ids.update(partial_dag.task_dict)
         else:
+            # Both directions must start from the requested tasks only. 
Merging upstream results
+            # before the downstream pass would also select every descendant of 
those upstream tasks.
+            relatives: set[str | tuple[str, int]] = set()
             if upstream:
-                _collect_relatives(dag_run_id, "upstream")
+                relatives.update(_find_relatives(dag_run_id, "upstream"))
             if downstream:
-                _collect_relatives(dag_run_id, "downstream")
+                relatives.update(_find_relatives(dag_run_id, "downstream"))
+            normal_task_ids.update(t for t in relatives if not isinstance(t, 
tuple))
+            mapped_tasks_tuples.update(t for t in relatives if isinstance(t, 
tuple))

Review Comment:
   `select_loop_clear_scope` had the same flaw, so in any Dag with a loop the 
downstream pass also walked from the upstream tasks and picked up their other 
descendants; when an upstream task sits outside the loop, that reached every 
iteration's gate, so clearing a task in iteration 1 reset the whole run and 
restarted the loop from iteration 0, and Mark as failed changed every 
iteration. Both passes now start from the selected task only, so the same clear 
selects just that task's relatives in iteration 1, and the PR description has 
the before/after table, tests and screenshots. One side effect: clears of a 
task inside a loop don't pair setups with teardowns, so an upstream setup's 
teardown that isn't downstream of the selected task is no longer selected, 
which matches Upstream-only; that pairing is left unchanged.



-- 
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