What is the purpose of task documentation in Airflow?
Task documentation in Airflow helps explain what a task does, making it easier for others (and yourself) to understand the workflow and maintain it over time.
Click to reveal answer
beginner
How do you add documentation to a task in Airflow?
You add documentation to a task by setting the 'doc_md' attribute with markdown text describing the task's purpose and details.
Click to reveal answer
beginner
What are tags used for in Airflow tasks?
Tags help organize and filter tasks in the Airflow UI, making it easier to find and group related tasks.
Click to reveal answer
beginner
How do you assign tags to a task in Airflow?
You assign tags by passing a list of strings to the 'tags' parameter when creating the task.
Click to reveal answer
intermediate
Why is it helpful to use both documentation and tags on Airflow tasks?
Documentation explains what the task does, while tags help organize tasks visually and functionally in the UI, improving workflow clarity and management.
Click to reveal answer
Which attribute is used to add markdown documentation to an Airflow task?
Adoc_string
Bdoc_md
Cdescription
Dtask_doc
✗ Incorrect
The 'doc_md' attribute is used to add markdown formatted documentation to an Airflow task.
How do tags help in Airflow task management?
AThey run tasks faster
BThey change task dependencies
CThey increase task priority
DThey organize and filter tasks in the UI
✗ Incorrect
Tags help organize and filter tasks in the Airflow UI, making it easier to find related tasks.
What data type should be used for the 'tags' parameter in an Airflow task?
AString
BInteger
CList of strings
DBoolean
✗ Incorrect
The 'tags' parameter expects a list of strings to assign multiple tags to a task.
Where can you see the documentation added to an Airflow task?
AIn the Airflow UI task details
BIn the task logs
CIn the DAG code only
DIn the scheduler logs
✗ Incorrect
Task documentation added via 'doc_md' is visible in the Airflow UI under the task details.
Which of the following is NOT a benefit of using tags in Airflow tasks?
AAutomatic task retries
BImproved task organization
CEasier task filtering
DBetter UI grouping
✗ Incorrect
Tags do not affect task retries; they are only for organization and filtering.
Explain how to add documentation and tags to an Airflow task and why each is useful.
Think about how documentation helps understanding and tags help finding tasks.
You got /4 concepts.
Describe the benefits of using task documentation and tags in managing Airflow workflows.
Consider how these features help both users and teams.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of adding documentation to an Airflow task using doc_md?
easy
A. To explain what the task does for better understanding
B. To change the task execution order
C. To assign tags for task grouping
D. To increase task execution speed
Solution
Step 1: Understand the role of doc_md in Airflow
doc_md is used to add markdown documentation to a task, explaining its purpose and behavior.
Step 2: Differentiate documentation from other features
Documentation does not affect execution order, tags, or speed; it only improves clarity.
Final Answer:
To explain what the task does for better understanding -> Option A
Quick Check:
Task documentation = Explanation [OK]
Hint: Documentation explains task purpose, not execution or tags [OK]
Common Mistakes:
Confusing documentation with tags
Thinking documentation changes task order
Assuming documentation affects performance
2. Which of the following is the correct way to add tags to an Airflow task in Python code?
easy
A. task = PythonOperator(task_id='task1', python_callable=my_func, tag='tag1')
B. task = PythonOperator(task_id='task1', python_callable=my_func, tags=['tag1', 'tag2'])
C. task = PythonOperator(task_id='task1', python_callable=my_func, tags='tag1,tag2')
D. task = PythonOperator(task_id='task1', python_callable=my_func, labels=['tag1', 'tag2'])
Solution
Step 1: Recall the correct parameter for tags
Airflow tasks accept a tags parameter as a list of strings to assign multiple tags.
Step 2: Check syntax correctness
task = PythonOperator(task_id='task1', python_callable=my_func, tags=['tag1', 'tag2']) uses tags=['tag1', 'tag2'] which is the correct syntax. Other options use incorrect parameter names or types.
Final Answer:
task = PythonOperator(task_id='task1', python_callable=my_func, tags=['tag1', 'tag2']) -> Option B
Quick Check:
Tags parameter = list of strings [OK]
Hint: Use tags as a list with key 'tags' in operator [OK]
Common Mistakes:
Using 'tag' instead of 'tags'
Passing tags as a comma string
Using 'labels' instead of 'tags'
3. Given this Airflow task code snippet, what will be the value of task.doc_md?
task = PythonOperator(
task_id='example_task',
python_callable=lambda: print('Hello'),
doc_md="""This task prints a greeting message."""
)
medium
A. None
B. "Prints a message"
C. SyntaxError
D. "This task prints a greeting message."
Solution
Step 1: Identify the doc_md assignment
The task is created with doc_md set to a triple-quoted string describing the task.
Step 2: Understand doc_md stores the documentation string
The doc_md attribute holds the exact string provided, so it will be "This task prints a greeting message.".
Final Answer:
"This task prints a greeting message." -> Option D
Quick Check:
doc_md value = given string [OK]
Hint: doc_md stores the exact documentation string given [OK]
Common Mistakes:
Assuming doc_md is None if not printed
Confusing doc_md with task output
Expecting syntax error from triple quotes
4. You wrote this Airflow task but it fails to assign tags properly:
A. Parameter should be 'tags' not 'tag'; fix by changing to tags=['data', 'etl']
B. PythonOperator does not support tags; remove the tag parameter
C. Tags must be a string, not a list; fix by tags='data,etl'
D. The task_id is invalid; change task_id to 'task_fail_1'
Solution
Step 1: Identify the incorrect parameter name
The code uses tag instead of the correct tags parameter for assigning tags.
Step 2: Correct the parameter name and keep the list format
Changing tag=['data', 'etl'] to tags=['data', 'etl'] fixes the issue.
Final Answer:
Parameter should be 'tags' not 'tag'; fix by changing to tags=['data', 'etl'] -> Option A
Quick Check:
Correct parameter name = tags [OK]
Hint: Use 'tags' plural, not 'tag' singular [OK]
Common Mistakes:
Using 'tag' instead of 'tags'
Passing tags as a string instead of list
Blaming task_id for tag issues
5. You want to organize your Airflow DAG tasks by adding documentation and tags. Which code snippet correctly adds both a markdown description and multiple tags to a task?
hard
A. task = PythonOperator(task_id='task1', python_callable=my_func, doc_md=['Runs ETL process'], tags='etl,daily')
B. task = PythonOperator(task_id='task1', python_callable=my_func, documentation='Runs ETL process', tag=['etl', 'daily'])
C. task = PythonOperator(task_id='task1', python_callable=my_func, doc_md='Runs ETL process', tags=['etl', 'daily'])
D. task = PythonOperator(task_id='task1', python_callable=my_func, doc_md='Runs ETL process', labels=['etl', 'daily'])
Solution
Step 1: Verify correct parameter names and types
doc_md should be a string with markdown text, and tags should be a list of strings.
Step 2: Check each option for correctness
task = PythonOperator(task_id='task1', python_callable=my_func, doc_md='Runs ETL process', tags=['etl', 'daily']) uses doc_md='Runs ETL process' (string) and tags=['etl', 'daily'] (list), which is correct. Others use wrong parameter names or types.