uranusjr commented on code in PR #32538:
URL: https://github.com/apache/airflow/pull/32538#discussion_r1260440104


##########
airflow/operators/python.py:
##########
@@ -251,24 +252,47 @@ def execute(self, context: Context) -> Any:
             self.log.info("Proceeding with downstream tasks...")
             return condition
 
-        downstream_tasks = context["task"].get_flat_relatives(upstream=False)
+        scope_teardowns = {x.task_id for x in 
self.get_upstreams_only_setups_and_teardowns() if x.is_teardown}
+
+        def is_relevant_teardown(other):
+            if other.task_id in scope_teardowns:
+                return True
+            elif other.is_teardown and not any(x.is_setup for x in 
other.upstream_list):
+                return True
+            else:
+                return False
+
+        downstream_tasks = [
+            x for x in context["task"].get_flat_relatives(upstream=False) if 
not is_relevant_teardown(x)
+        ]
         self.log.debug("Downstream task IDs %s", downstream_tasks)
 
         if downstream_tasks:
             dag_run = context["dag_run"]
             execution_date = dag_run.execution_date
-
+            if TYPE_CHECKING:
+                assert isinstance(execution_date, DateTime)
             if self.ignore_downstream_trigger_rules is True:
                 self.log.info("Skipping all downstream tasks...")
-                self.skip(dag_run, execution_date, downstream_tasks, 
map_index=context["ti"].map_index)
+                self.skip(
+                    dag_run=dag_run,
+                    execution_date=execution_date,
+                    tasks=downstream_tasks,
+                    map_index=context["ti"].map_index,
+                )
             else:
                 self.log.info("Skipping downstream tasks while respecting 
trigger rules...")
                 # Explicitly setting the state of the direct, downstream 
task(s) to "skipped" and letting the
                 # Scheduler handle the remaining downstream task(s) 
appropriately.
+                to_skip = [
+                    x
+                    for x in 
context["task"].get_direct_relatives(upstream=False)
+                    if not is_relevant_teardown(x)
+                ]

Review Comment:
   Need a comment around here to explain why relevant teardowns should not be 
skipped. Same for the call above.



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