What if you could run your workflows exactly when and how you want, without any hassle?
Why Manual triggers and parameters in Apache Airflow? - Purpose & Use Cases
Imagine you have a complex workflow that runs every day automatically, but sometimes you need to run it right now with special settings. You try to do this by stopping the whole system, changing files, and restarting everything manually.
This manual way is slow and risky. You might forget to change something back, make typos, or cause delays. It's like trying to fix a car engine while driving it--stressful and error-prone.
Manual triggers with parameters let you start workflows instantly with custom inputs, without stopping or changing code. It's like pressing a button and telling the system exactly what you want, safely and quickly.
Edit config file
Restart scheduler
Wait for runTrigger DAG manually
Set parameters in UI
Run immediatelyYou can react fast to urgent needs and test different scenarios easily by running workflows on demand with custom settings.
A data team needs to reload yesterday's sales data after fixing a bug. Instead of waiting for the next scheduled run, they trigger the workflow manually with the corrected date parameter and get results instantly.
Manual triggers let you run workflows anytime without waiting.
Parameters customize each run without changing code.
This saves time and reduces errors in urgent situations.
Practice
Solution
Step 1: Understand manual trigger concept
Manual triggers allow users to start a workflow whenever they want, not waiting for a schedule.Step 2: Recognize parameter use
Manual triggers can include parameters to customize the run, making the workflow flexible.Final Answer:
To start a workflow immediately with optional custom parameters -> Option DQuick Check:
Manual trigger = immediate start + parameters [OK]
- Confusing manual trigger with scheduled runs
- Thinking manual trigger stops a DAG
- Assuming manual trigger deletes DAG
Solution
Step 1: Recall parameter access method
Parameters passed during manual trigger are accessed via dag_run.conf dictionary.Step 2: Use safe access method
Using dag_run.conf.get('user_id') safely returns the value or None if missing, avoiding errors.Final Answer:
user_id = dag_run.conf.get('user_id') -> Option AQuick Check:
Use dag_run.conf.get() to read parameters [OK]
- Using square brackets without .get() causing KeyError
- Using non-existent dag_run.params
- Calling dag_run.get() which is invalid
def greet(**context):
name = context['dag_run'].conf.get('name', 'Guest')
print(f"Hello, {name}!")
What will be printed if the DAG is manually triggered with parameters {'name': 'Alice'}?Solution
Step 1: Understand parameter retrieval
The code uses dag_run.conf.get('name', 'Guest') which returns 'Alice' if passed, else 'Guest'.Step 2: Apply given parameters
Since 'name' is provided as 'Alice', the print statement outputs "Hello, Alice!".Final Answer:
Hello, Alice! -> Option BQuick Check:
Parameter 'name' passed = 'Alice' printed [OK]
- Ignoring default value and expecting error
- Assuming parameter is missing
- Confusing print output with variable name
def process(**kwargs):
param = kwargs['dag_run'].conf['param']
print(param)
When manually triggering the DAG without passing 'param', what happens?Solution
Step 1: Analyze parameter access method
Accessing dag_run.conf['param'] without .get() causes KeyError if 'param' is missing.Step 2: Understand missing parameter effect
Since 'param' is not passed, the code raises KeyError and does not print anything.Final Answer:
Raises KeyError exception -> Option AQuick Check:
Missing key with [] causes KeyError [OK]
- Expecting None or empty string instead of error
- Assuming print outputs 'param' string
- Not realizing [] access throws error
Solution
Step 1: Understand default parameter handling
Using dag_run.conf.get('order_id', 'unknown') returns 'order_id' if present, else 'unknown'.Step 2: Compare options for correctness
A fails with KeyError if missing. B checks if conf exists (empty {} is falsy), but if other parameters present conf is truthy causing KeyError. C works for missing but overrides falsy values like empty string. D is clean, safe, and handles all cases correctly.Final Answer:
order_id = dag_run.conf.get('order_id', 'unknown') -> Option CQuick Check:
Use .get(key, default) for safe defaults [OK]
- Using [] without checking key existence
- Using or without default in .get()
- Overcomplicating with if-else instead of .get()
Ready to prove it?
Pass the test and this pattern moves unknown
