When manually triggering the DAG without passing 'param', what happens?
medium
A. Raises KeyError exception
B. Prints empty string
C. Prints None
D. Prints 'param'
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 A
Quick Check:
Missing key with [] causes KeyError [OK]
Hint: Use .get() to avoid KeyError on missing params [OK]
Common Mistakes:
Expecting None or empty string instead of error
Assuming print outputs 'param' string
Not realizing [] access throws error
5. You want to manually trigger a DAG that processes orders. The DAG expects a parameter 'order_id'. You want to ensure the DAG uses 'unknown' if 'order_id' is missing. Which code snippet inside the DAG task correctly implements this?
hard
A. order_id = dag_run.conf['order_id'] or 'unknown'
B. order_id = dag_run.conf['order_id'] if dag_run.conf else 'unknown'
C. order_id = dag_run.conf.get('order_id', 'unknown')
D. order_id = dag_run.conf.get('order_id') or 'unknown'
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 C
Quick Check:
Use .get(key, default) for safe defaults [OK]
Hint: Use .get(key, default) to set fallback values [OK]
Common Mistakes:
Using [] without checking key existence
Using or without default in .get()
Overcomplicating with if-else instead of .get()
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.