Trigger rules and run state
By default a task runs only when everything before it succeeded. That is right for most steps, and wrong for clean-up tasks and joins after a branch. Trigger rules change the condition. This lesson shows the useful ones.
Pipelines in production · Airflow · Silver · Failures, lesson 2 of 2
On this page
Read first: Retries, timeouts and callbacks (skip if you know it)
In plain words first
A relay runner normally starts only when the teammate before them finishes. But the person who packs up the kit after the race goes whatever happened, even if a runner dropped out.
A trigger rule is that condition for each tasktask: One step of a DAG, such as running a query or calling an API. Each run of a task for one date is a task instance. Learn more →: "all before me succeeded" by default, or "whatever happened", "at least one succeeded" and others.
all_success, the default
A task runs when all its upstream tasks succeeded. If one failed, it becomes upstream_failed; if one was skipped, it is skipped too. That is right for a chain of dependent steps and wrong for two kinds of task: clean-up that must always run, and alerts that should run only when something failed.
| trigger_rule | Runs when the upstream tasks are... | Typical use |
|---|---|---|
all_success | all successful | The normal step |
all_done | all finished, whatever their state | Clean-up: delete temp tables, stop a cluster |
one_failed | any failed (does not wait for the rest) | Send an alert |
all_failed | all failed or upstream_failed | A fallback path |
one_success | any successful (does not wait) | The first of several sources to arrive |
none_failed | all finished, none failed (skipped is fine) | After optional steps |
none_failed_min_one_success | as none_failed, and at least one succeeded | The join after a branch |
always | immediately, without waiting | Rarely: monitoring side tasks |
How a run gets its state
When every task has finished, Airflow looks at the leaf tasks, the ones with nothing downstream. If any leaf is failed or upstream_failed, the run is failed; otherwise it succeeded. Upstream failures only count through the leaves. That rule plus all_done produces a classic surprise:
import pendulum from datetime import timedelta from airflow.sdk import DAG from airflow.providers.standard.operators.bash import BashOperator with DAG( dag_id="plays_rollup", schedule="0 3 * * *", start_date=pendulum.datetime(2026, 3, 1, tz="UTC"), catchup=True, default_args={"retries": 2, "retry_delay": timedelta(minutes=5)}, ): ingest = BashOperator(task_id="ingest", bash_command="ingest_plays --day {{ ds }}") rollup = BashOperator(task_id="rollup", bash_command="rollup_plays --day {{ ds }}") drop_tmp = BashOperator( task_id="drop_tmp", bash_command="drop_tmp_tables --day {{ ds }}", trigger_rule="all_done" ) ingest >> rollup >> drop_tmp
What the schedulerscheduler: The Airflow process that reads DAG files, creates runs when they are due, and queues the tasks whose upstream tasks are done. Learn more → does · deployed Mar 3, 10:00 UTC · grid as of Mar 3, 12:00 UTC · failing: rollup in the 2026-03-02 run · 0 3 * * * (CronTriggerTimetable)
| task \ run | Mar 1 03:00 | Mar 2 03:00 | Mar 3 03:00 |
|---|---|---|---|
| ingest | |||
| rollup | 3 | ||
| drop_tmp |
successfailed· the bar on top is the run's state; a number is how many tries
Look at the 2 March run: rollup failed after three tries, yet the run is green. Its only leaf, drop_tmp, ran (that is what all_done is for) and succeeded, so the run succeeded. Dashboards and alerts that watch run states never hear about the failure.
Clean up and still fail the run
- 1Setup and teardown. Mark the clean-up as a teardown:
drop_tmp.as_teardown(setups=ingest). A teardown runs likeall_done, but it is ignored when Airflow decides the run's state, so the run fails whenrollupfails. This is the modern answer; Task groupstask group: A named box of related tasks in a DAG, shown collapsed in the UI and wired as one unit. Learn more →, setup and teardown covers it. - 2A watcher task. Add a leaf with
trigger_rule="one_failed"downstream of the real work, whose code raises an exception. It is skipped on good days and fails when anything failed, taking the run with it.
from airflow.sdk import TriggerRule from airflow.sdk.exceptions import AirflowFailException # the enum, instead of the string @task(trigger_rule=TriggerRule.ONE_FAILED, retries=0) def fail_run_if_upstream_failed(): raise AirflowFailException("Upstream work failed; failing this run on purpose.") [ingest, rollup] >> fail_run_if_upstream_failed()
Common mistakes
- Clean-up with the default all_success — It is skipped exactly when the work failed and the clean-up matters most.
- A clean-up or alert task as the only leaf — The run is marked success even when the work failed.
- one_failed alerts that wait for "the end" — one_failed fires as soon as one upstream fails; that is usually what you want.
- all_done after a branch — It also runs when the branch it depends on failed.
Key takeaways
- all_success (default): a failed upstream makes a task upstream_failed; a skipped one skips it.
- all_done for clean-up, one_failed for alerts, none_failed_min_one_success to join branches.
- A run's state comes from its leaves.
- Teardowns or a watcher keep clean-up from hiding failures.
Interview prep
THE QUESTION
"A clean-up task with trigger_rule=all_done is the last task of a DAG. The main job fails but the run shows success. Why, and how do you fix it?"
Avoid: "all_done on the clean-up task" as the whole answer, without noticing that the clean-up then decides the run's state.
Follow-ups · answer out loud, then open
Follow-up"What is the difference between none_failed and none_failed_min_one_success?"
Scenario"You need a Slack alert when any of four extract tasks fails, as soon as it fails. How?"
Trap"A failed task anywhere in the DAG fails the run."
Check yourself
3 questionsTask C (all_success) has upstream A (success) and B (skipped). What is C?
Show the answer
skipped. Under all_success, a skipped upstream task skips the task.
The only leaf of a run succeeded, but a task before it failed. What is the run's state?
Show the answer
success. Run state comes from the leaves.
Which rule fits an alert task that should fire as soon as something fails?
Show the answer
one_failed. one_failed runs as soon as one upstream task has failed.
Practise this
Problems that use this, graded on hidden tests
Keep going
Up next · new module: Control flow · 4 min readBranching and short-circuiting
Choose a path at run time, skip the rest, and join the branches back together.
Related lessons
Retries, timeouts and callbacksAirflow · 5 min read
Task groups, setup and teardown
Previous: Retries, timeouts and callbacks
Primary sources: Trigger rules · Setup and teardown