ashb commented on a change in pull request #7276: [AIRFLOW-5391] Do not run 
skipped tasks when they are cleared
URL: https://github.com/apache/airflow/pull/7276#discussion_r381943188
 
 

 ##########
 File path: airflow/models/skipmixin.py
 ##########
 @@ -65,13 +68,53 @@ def skip(self, dag_run, execution_date, tasks, 
session=None):
                 ti.end_date = now
                 session.merge(ti)
 
-            session.commit()
+    @provide_session
+    def skip(
+        self, dag_run, execution_date, tasks, session=None,
+    ):
+        """
+        Sets tasks instances to skipped from the same dag run.
+        If `task_id` is a valid attribute, store the list of skipped task IDs 
to XCom
+        so that NotPreviouslySkippedDep knows these tasks should be skipped 
when they
+        are cleared.
+
+        :param dag_run: the DagRun for which to set the tasks to skipped
+        :param execution_date: execution_date
+        :param tasks: tasks to skip (not task_ids)
+        :param session: db session to use
+        """
+        if not tasks:
+            return
+
+        self._set_state_to_skipped(dag_run, execution_date, tasks, session)
+        session.commit()
+
+        # SkipMixin may not necessarily have a task_id attribute. Only store 
to XCom if one is available.
+        try:
+            task_id = self.task_id
+        except AttributeError:
+            task_id = None
+
+        if task_id is not None:
+            from airflow.models.xcom import XCom
+
+            XCom.set(
+                key=XCOM_SKIPMIXIN_KEY,
+                value={XCOM_SKIPMIXIN_SKIPPED: [d.task_id for d in tasks]},
+                task_id=task_id,
+                dag_id=dag_run.dag_id,
+                execution_date=dag_run.execution_date,
+            )
 
-    def skip_all_except(self, ti: TaskInstance, branch_task_ids: Union[str, 
Iterable[str]]):
+    def skip_all_except(
+        self, ti: TaskInstance, branch_task_ids: Union[str, Iterable[str]]
+    ):
         """
         This method implements the logic for a branching operator; given a 
single
         task ID or list of task IDs to follow, this skips all other tasks
-        immediately downstream of this operator.
+        immediately downstream of this operator. branch_task_ids is stored to 
XCom so that
 
 Review comment:
   ```suggestion
           immediately downstream of this operator.
           
           branch_task_ids is stored to XCom so that
   ```
   
   (Plus reformat.)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to