airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Common tasks in downstream of multiple branches always set to skipped

Open CodingJonas opened this issue 6 years ago • 4 comments

Apache Airflow version: 1.10.9

Environment:

  • OS: Ubuntu 18.04
  • Kernel:
Linux DELL-5540-01 4.15.0-1076-oem #86-Ubuntu SMP Wed Mar 4 05:40:20 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

What happened:

Two branches join into the same task at one point of their downstream. This joint task and all following ones will set to be skipped due to one of the two branches being skipped.

What you expected to happen:

No matter which branch is chosen, the joint downstream should never be skipped, since at least one of the branches will end up into this joint downstream.

How to reproduce it: I followed the code of this issue (AIRFLOW-3823) since it was, as I understood it, exactly about my issue. It works as described in the issue, but choosing the other branch will cause the rest of the DAG to be skipped.

import airflow
from airflow.models import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import BranchPythonOperator
args = {"owner": "airflow", "start_date": airflow.utils.dates.days_ago(14)}
dag = DAG(
 dag_id="branch_test",
 default_args=args,
 schedule_interval="0 0 * * *",
)
branch = BranchPythonOperator(task_id="branch", python_callable=lambda: "t4", dag=dag)
t1 = DummyOperator(task_id="t1", dag=dag)
t2 = DummyOperator(task_id="t2", dag=dag)
t3 = DummyOperator(task_id="t3", dag=dag)
t4 = DummyOperator(task_id="t4", dag=dag)
t5 = DummyOperator(task_id="t5", dag=dag)
branch >> t1 >> t2 >> t3 >> t4
branch >> t4
t4 >> t5

screenshot

You can include images using the .md sytle of alt text

CodingJonas avatar Mar 26 '20 13:03 CodingJonas

Thanks for opening your first issue here! Be sure to follow the issue template!

boring-cyborg[bot] avatar Mar 26 '20 13:03 boring-cyborg[bot]

This is expected behavior, and is actually listed explicitly as a possible scenario in the docs: https://airflow.apache.org/docs/stable/concepts.html?highlight=branch#trigger-rules

This can be resolved by setting the trigger_rule of t4 to none_failed.

madison-ookla avatar Mar 26 '20 13:03 madison-ookla

Thanks for the quick reply. Changing the trigger worked, but seems quite unintuitive to me in the first place. But that's on me. Have to learn more about this framework :)

CodingJonas avatar Mar 26 '20 13:03 CodingJonas

Thanks for the quick reply. Changing the trigger worked, but seems quite unintuitive to me in the first place. But that's on me. Have to learn more about this framework :)

Read those docs! Hopefully they'll help too :) Best of luck 👍

madison-ookla avatar Mar 26 '20 13:03 madison-ookla