Airflow Trigger Rules
A trigger rule tells a task what to expect from the tasks before it. By default, a task runs only when all earlier tasks succeed. Trigger rules change that behavior, so you can build cleanup steps, alerts, and flexible joins.
The Group Project Picture
Picture a school group project with three students who each write one page. The teacher can set different rules for the final binding step. One rule says "bind only when all three finish." Another says "bind when at least one finishes." A third says "bind no matter what happened." Trigger rules offer the same choices.
Student A ─┐ Student B ─┼──► Bind the report ← trigger rule decides when this runs Student C ─┘
The Default Rule
The default rule is all_success. A task with this rule waits for every parent to succeed. One failed parent turns the child into upstream_failed, and the child never runs.
All Trigger Rules
| Rule | Task Runs When |
|---|---|
all_success | Every parent succeeded (default) |
all_failed | Every parent failed |
all_done | Every parent finished, in any state |
all_skipped | Every parent was skipped |
one_success | At least one parent succeeded |
one_failed | At least one parent failed |
one_done | At least one parent succeeded or failed |
none_failed | No parent failed. Skipped parents are fine |
none_failed_min_one_success | No parent failed, and at least one succeeded |
none_skipped | No parent was skipped |
always | Runs regardless of parent states |
How to Set a Rule
from airflow.operators.python import PythonOperator
cleanup = PythonOperator(
task_id="cleanup",
python_callable=remove_temp_files,
trigger_rule="all_done",
)
Use Case 1: Cleanup That Always Runs
A pipeline creates temporary files. The cleanup task must delete them even when the main work fails. The rule all_done guarantees that.
extract ──► transform ──► load ──► cleanup (all_done)
│
even if this fails, cleanup still runs
Use Case 2: Alert on Failure
An alert task should fire only when something goes wrong. The rule one_failed sends the message only after a failure.
alert = PythonOperator(
task_id="send_alert",
python_callable=notify_team,
trigger_rule="one_failed",
)
[extract, transform, load] >> alert
When all three tasks succeed, the alert task is skipped.
Use Case 3: Join After a Branch
A branch skips one of its paths. A join task with the default rule would see a skipped parent and skip itself. The rule none_failed_min_one_success fixes this.
┌──► path_a ──┐
start ──► │ ├──► join (none_failed_min_one_success)
(branch) └──► path_b ──┘
one path runs, one is skipped
Use Case 4: Take the Fastest Source
Two providers deliver the same data. The rule one_success starts the next step as soon as either one arrives.
Rule Behavior Example
Assume three parents finish as success, failed, and skipped.
| Rule | Does the Child Run? |
|---|---|
| all_success | No |
| all_done | Yes |
| one_success | Yes |
| one_failed | Yes |
| none_failed | No |
| none_skipped | No |
Common Mistakes
- Leaving the default rule on a join task after a branch, which skips the join.
- Using
all_failedfor an alert whenone_failedfits better. - Using
alwaysfor a task that needs real input data from its parents.
Key Takeaways
- A trigger rule describes which parent states allow a task to start.
- The default
all_successworks for most steps. - Use
all_donefor cleanup andone_failedfor alerts. - Use
none_failed_min_one_successfor joins after branches.
