Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 37 ยท Sensors, Branching and Dynamic DAGs

Airflow Trigger Rules: When Does a Task Run?

Learn every common Airflow trigger rule (all_success, all_done, one_failed, none_failed and more), how upstream states decide, cleanup patterns and a runnable rule evaluator.

A task does not run just because the previous one finished. The scheduler checks the states of its upstream tasks against the task's trigger rule. The default rule, all_success, says "run only if every parent succeeded". Change the rule and you can build cleanup tasks that always run, alerts that fire on failure and joins that survive skipped branches.

Airflow is not available on this site, so Airflow code is read-only. The runnable example is a stand-in that evaluates the rules in plain Python.

Task states you need to know

Each task instance ends a run in a state. The ones that matter here:

  • success, failed
  • skipped (for example the other side of a branch)
  • upstream_failed (an upstream task failed, so this one never ran)

A task's rule looks at the states of its direct parents only.

The rules

Rule Runs when...
all_success (default) every parent succeeded
all_failed every parent failed or is upstream_failed
all_done every parent finished, whatever the result
all_skipped every parent was skipped
one_success at least one parent succeeded (does not wait for the others)
one_failed at least one parent failed (does not wait for the others)
one_done at least one parent succeeded or failed
none_failed no parent failed or is upstream_failed (skipped is fine)
none_failed_min_one_success no parent failed and at least one succeeded
none_skipped no parent was skipped
always run regardless of the parents' states

You set it on any task or operator:

Python
from airflow.providers.standard.operators.empty import EmptyOperator
from airflow.sdk import task

@task(trigger_rule="one_failed")
def alert():
    print("something failed upstream")

cleanup = EmptyOperator(task_id="cleanup", trigger_rule="all_done")

Evaluating the rules yourself

This stand-in (not Airflow's code) implements the rules as small functions, then prints a table for four different parent combinations. Run it and compare with the table above.

Python Stand-in: trigger rule evaluator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the ok+skip column: all_success does not run, none_failed and none_failed_min_one_success do. For skip+skip, only none_failed runs, because none_failed_min_one_success needs one real success.

Three patterns worth memorising

1. Cleanup that always runs. A task that deletes temporary files or shuts down a cluster should run even if the work failed:

Python
extract >> transform >> load >> cleanup    # cleanup has trigger_rule="all_done"

Airflow also offers @teardown tasks and setup/teardown pairs that make this intent explicit and tie the cleanup to the task that needs it: if the setup task succeeds, teardown always runs.

2. An alert on failure. Put an alert task downstream of the risky ones with one_failed. It is skipped in healthy runs and runs only when a parent fails. For many tasks, a DAG-level on_failure_callback is often neater (alerting lesson).

3. A join after a branch. Use none_failed_min_one_success, because the skipped path must not block the join.

Python Stand-in: cleanup and alert on a failed run

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

report is upstream_failed (never ran), while cleanup and alert ran. That is what you want.

Pitfalls

  • Rules look only at direct parents. A rule on a task two steps away does not see the failure unless the state propagates (an upstream_failed parent counts as failed for the child).
  • one_success and one_failed do not wait for the other parents; the task can start while siblings are still running.
  • all_done runs even when the DAG run is being cancelled, which is the point for cleanup but surprising otherwise.
  • always ignores everything, including upstream failures; use it sparingly.
  • Mapped tasks (next lesson) apply the rule to all their instances at once.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which rule makes a cleanup task run whether upstream tasks succeeded or failed?

    all_done runs when every parent has finished, regardless of its result.
  2. 2. Parents: one success and one skipped. Which rule does NOT run the task?

    all_success requires every parent to have succeeded; a skipped parent breaks it.
  3. 3. What is special about one_failed?

    one_failed (and one_success) trigger as soon as one parent reaches that state.
  4. 4. Both parents were skipped. Which rule still runs the task?

    none_failed only demands that nothing failed. The min_one_success variant also needs a real success.

Summary

  • A trigger rule compares the states of a task's direct parents to decide whether it runs.
  • all_success is the default; all_done is for cleanup; one_failed for alerts; none_failed_min_one_success for joins after branches.
  • Rules such as one_success and one_failed do not wait for the remaining parents.
  • Use setup and teardown tasks to make cleanup intent explicit.

Next: Dynamic Task Mapping