You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/08 15:24:26 UTC

[GitHub] [airflow] yuqian90 commented on a change in pull request #7464: [AIRFLOW-4453] Make behavior of `none_failed` consistent with documentation

yuqian90 commented on a change in pull request #7464: [AIRFLOW-4453] Make behavior of `none_failed` consistent with documentation
URL: https://github.com/apache/airflow/pull/7464#discussion_r389379398
 
 

 ##########
 File path: airflow/operators/python.py
 ##########
 @@ -167,6 +167,34 @@ def execute(self, context: Dict):
         return branch
 
 
+def create_branch_join(branch_operator, *args, **kwargs):
+    """
+    Create a join task for a branching logic. This join task is always executed regardless
+    of which branches are followed. It is only skipped if the ``branch_operator`` is skipped.
+    """
+    def python_callable(ti, **_):
+        from airflow.utils.session import create_session
+        from airflow.exceptions import AirflowSkipException
+        from airflow.utils.state import State
+        from airflow.models import TaskInstance
+
+        with create_session() as session:
+            branch_ti = session.query(TaskInstance).filter(
+                TaskInstance.dag_id == ti.dag_id,
+                TaskInstance.task_id == branch_operator.task_id,
+                TaskInstance.execution_date == ti.execution_date
+            ).one_or_none()
+
+            if not branch_ti:
+                return
+
+            if branch_ti.state == State.SKIPPED:
+                raise AirflowSkipException(f"Skipping because parent task {branch_operator.task_id} "
+                                           "is skipped.")
 
 Review comment:
   Hi, @kaxil I've done the renaming you suggested to `create_branch_join_task()`. 
   
   Any suggestion about how to make `join_2` skipped other than raising `AirflowSkipException`?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services