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/09 17:13:07 UTC

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

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

 ##########
 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:
   What do you think of having 2 trigger rules? 
   
   1) Fixed "none_failed"
   2) none_failed_or_skipped
   
   (2) can be used to get current "non_failed" like feature, isn't it?

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