Skip to main content

Trigger Rules in Apache Airflow

Deciding When a Task Should Run ⏱️​

The Story: Success Isn’t Always Required​

Imagine this situation:

  • One branch succeeds
  • Another branch is skipped
  • A third branch fails

Now a downstream task asks:

β€œShould I run?”

By default, Airflow answers:

β€œOnly if everything succeeded.”

But real-world workflows are more nuanced.

That’s why Trigger Rules exist β€”
to precisely control when a task is allowed to execute.


What Are Trigger Rules?​

A trigger rule defines the conditions under which a task runs, based on the state of its upstream tasks.

Trigger rules evaluate:

  • Success
  • Failure
  • Skipped
  • Upstream completion states

Default Trigger Rule​

all_success

Meaning:

  • Every upstream task must succeed
  • Any failure or skip prevents execution

This is safe β€” but often too strict.


Why Trigger Rules Matter​

Without custom trigger rules:

  • Branching breaks downstream logic
  • Cleanup tasks don’t run
  • Notifications don’t fire
  • DAGs behave unexpectedly

With trigger rules:

  • Pipelines become predictable
  • Edge cases are handled
  • DAGs become production-ready

Most Common Trigger Rules Explained​

1. all_success (Default)​

βœ” All upstream tasks must succeed
❌ Any failure or skip blocks execution

Use case: Critical processing steps


2. all_failed​

βœ” Runs only if all upstream tasks fail

Use case: Failure handling, rollback logic


3. one_success​

βœ” Runs if at least one upstream succeeds

Use case: Aggregation from multiple sources


4. one_failed​

βœ” Runs if at least one upstream fails

Use case: Alerting and incident handling


5. none_failed​

βœ” No upstream task has failed
❌ Skipped tasks are allowed

Use case: Soft validation logic


6. none_skipped​

βœ” No upstream task is skipped

Use case: Strict branching enforcement


7. none_failed_min_one_success ⭐ (Very Important)​

βœ” No failures
βœ” At least one success
❌ Skips allowed

Use case: Branching workflows

This is the most commonly used trigger rule after BranchPythonOperator.


8. all_done​

βœ” Runs once all upstream tasks finish, regardless of outcome

Use case: Cleanup, logging, metrics


Visual Example: Branching + Trigger Rules​

Scenario​

  • Branch A β†’ Success
  • Branch B β†’ Skipped

Downstream behavior:

Trigger RuleWill Task Run?
all_success❌ No
one_successβœ… Yes
none_failed_min_one_successβœ… Yes
all_doneβœ… Yes

Practical Example: Branching with Trigger Rule​

from airflow import DAG
from airflow.operators.python import BranchPythonOperator, PythonOperator
from airflow.utils.trigger_rule import TriggerRule
from datetime import datetime

def choose_path():
return "path_a"

def path_a():
print("Path A executed")

def path_b():
print("Path B executed")

def final_task():
print("Final task executed")

with DAG(
dag_id="trigger_rule_example",
start_date=datetime(2024, 1, 1),
schedule_interval=None,
catchup=False,
) as dag:

branch = BranchPythonOperator(
task_id="branch",
python_callable=choose_path
)

task_a = PythonOperator(
task_id="path_a",
python_callable=path_a
)

task_b = PythonOperator(
task_id="path_b",
python_callable=path_b
)

final = PythonOperator(
task_id="final_task",
python_callable=final_task,
trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS
)

branch >> [task_a, task_b] >> final

Input & Output Example​

Branch Decision

"path_a"

Task States

path_a β†’ success
path_b β†’ skipped
final_task β†’ success

Trigger Rules with ShortCircuitOperator​

By default:

  • ShortCircuit skips everything downstream

To allow a task to always run:

trigger_rule="all_done"

Use case: Notifications, audits, cleanup


Trigger Rules with TaskFlow API​

@task(trigger_rule="all_done")
def cleanup():
print("Cleanup completed")

Common Mistakes​

❌ Forgetting trigger rules after branching
❌ Using all_success blindly
❌ Expecting skipped tasks to count as success
❌ Not documenting trigger behavior


Best Practices​

βœ… Explicitly define trigger rules
βœ… Use none_failed_min_one_success after branches
βœ… Use all_done for cleanup tasks
βœ… Keep DAG logic readable


Summary πŸ§ β€‹

  • Trigger rules control task execution timing
  • Default all_success is often too strict
  • Branching requires special trigger rules
  • Cleanup tasks should use all_done
  • Trigger rules make DAGs predictable

Key Takeaways​

  • Trigger rules evaluate upstream task states
  • Skips matter as much as failures
  • Correct trigger rules prevent broken DAGs
  • Essential for branching & short-circuit logic

What’s Next?​

➑️ Dynamic Tasks – TaskFlow API & @task decorator
Learn how Airflow creates tasks dynamically at runtime using modern patterns.