Apache Airflow DAG Authoring

Question bank

Astronomer logo

Apache Airflow DAG Authoring

AF3-DA

43 Apache Airflow DAG Authoring questions with the correct answer and a written explanation, organised across 5 exam domains.

43 questions
5 domains
Foundation level

Question index

Jump straight to any question. Answers and explanations are inline.

Advanced DAG Authoring

11 questions in this domain

  1. Question 1Single Choice

    What is the purpose of Jinja templating in Apache Airflow?

    • ATo define DAG structure at parse time
    • BTo evaluate expressions at runtime within templated fieldsCorrect answer
    • CTo replace Python in operator arguments
    • DTo generate dynamic DAG IDs

    Why this is the answer

    Jinja templating allows dynamic values to be computed at task execution time, not during DAG parsing. Only certain operator fields support templating.

  2. Question 2Multiple Select

    Which of the following are valid ways to parameterize a DAG? (Select all that apply)

    • AUsing f-strings in DAG definitionCorrect answer
    • BUsing Jinja templates in default_args
    • CUsing dag_run.conf in templated fieldsCorrect answer
    • DUsing environment variables at parse timeCorrect answer

    Why this is the answer

    f-strings work at parse time, dag_run.conf runtime, environment variables parse time. default_args does not support templating.

  3. Question 3Interactive

    What type of DAG authoring pattern is demonstrated in the code?

    • AStatic DAG
    • BDynamic DAG factoryCorrect answer
    • CDynamic task mapping
    • DTriggered DAG

    Why this is the answer

    The code uses a function to create DAG objects based on a list, which is the DAG factory pattern.

  4. Question 4Single Choice

    What happens when a BranchPythonOperator returns the task_id of a task that does not exist?

    • AThe DAG fails immediately
    • BThe task is skipped
    • CAirflow raises a ValueErrorCorrect answer
    • DThe branching operator defaults to all downstream tasks

    Why this is the answer

    The BranchPythonOperator requires that the returned task id matches an existing downstream task; otherwise it raises an error.

  5. Question 5Multiple Select

    Which of the following trigger rules allow a task to run even if upstream tasks are skipped? (Select all that apply)

    • Aall_success
    • Ball_doneCorrect answer
    • Cnone_failedCorrect answer
    • Done_successCorrect answer

    Why this is the answer

    all_done runs regardless of state, none_failed allows skipped, one_success allows at least one success.

  6. Question 6Interactive

    What should the return type of a branch function be for a single downstream task?

    • AA stringCorrect answer
    • BA list of strings
    • CA boolean
    • DNone

    Why this is the answer

    The branch function should return the task_id of the downstream task to execute, which is a string.

  7. Question 7Single Choice

    In the TaskFlow API, how does Airflow automatically infer task dependencies?

    • ABy reading function decorators
    • BBy matching parameter names to upstream task namesCorrect answer
    • CBy analyzing docstrings
    • DBy scanning import statements

    Why this is the answer

    When a task function has a parameter with the same name as an upstream task's function name, Airflow creates a dependency and passes the return value via XCom.

  8. Question 8Multiple Select

    Which of the following are benefits of using the @task decorator over traditional PythonOperator? (Select all that apply)

    • AAutomatic XCom passingCorrect answer
    • BSupport for manual context provision
    • CCleaner code with less boilerplateCorrect answer
    • DAbility to use any operator type

    Why this is the answer

    @task automatically passes XComs and reduces boilerplate. It does not support all operator types.

  9. Question 9Interactive

    Is the given DAG correctly structured for TaskFlow XCom passing?

    • AYes, dependencies are correctly set
    • BNo, transform should be called with extract() as argumentCorrect answer
    • CNo, schedule must be defined in DAG constructor
    • DNo, extract() and transform() are not distinct tasks

    Why this is the answer

    Using >> sets dependencies but does not pass XCom; TaskFlow requires function call syntax to pass return values.

  10. Question 10Single Choice

    What is the purpose of a Pool in Apache Airflow?

    • ATo limit the number of active DAG runs
    • BTo restrict concurrency for specific resourcesCorrect answer
    • CTo increase task priority
    • DTo store connection credentials

    Why this is the answer

    Pools control the number of tasks that can use a shared resource simultaneously.

  11. Question 11Multiple Select

    Which factors influence the order in which tasks are scheduled within a pool? (Select all that apply)

    • Apriority_weightCorrect answer
    • Bweight_ruleCorrect answer
    • Cstart_date
    • Dexecution_timeout

    Why this is the answer

    Priority weight and weight_rule determine scheduling order within a pool. start_date and timeout do not affect queuing order.

DAG Development Fundamentals

11 questions in this domain

  1. Question 12Single Choice

    What is the recommended pattern for defining a DAG in Airflow 2.x?

    • AUsing the `with DAG(...)` context manager
    • BUsing the `@dag` decoratorCorrect answer
    • CUsing the `dag = DAG(...)` constructor without context
    • DUsing a YAML configuration file

    Why this is the answer

    The `@dag` decorator is the recommended pattern in Airflow 2.x for its conciseness and alignment with Python function-based design.

  2. Question 13Multiple Select

    Which of the following are valid ways to attach a task to a DAG? (Select two)

    • AInstantiate the operator inside a `with DAG(...)` blockCorrect answer
    • BPass the `dag` parameter to the operator constructorCorrect answer
    • CDefine the operator after the `with` block has ended
    • DUse the `dag_id` parameter instead of the `dag` object

    Why this is the answer

    Operators inside a `with DAG(...)` block are automatically attached. Alternatively, passing `dag` explicitly also works.

  3. Question 14Interactive

    Examine the DAG code in the code block. What is the critical mistake that will cause an import error?

    • AThe function does not return the DAG objectCorrect answer
    • BThe `@dag` decorator is missing parentheses
    • CThe `schedule` parameter should be `schedule_interval`
    • DThe `start_date` uses `datetime` without timezone

    Why this is the answer

    The `@dag` decorator expects the decorated function to return the DAG object. Omitting `return dag` causes an import error.

  4. Question 15Single Choice

    What does the `default_args` dictionary provide in an Airflow DAG?

    • AIt defines the schedule and start date of the DAG
    • BIt sets default parameter values for all tasks in the DAGCorrect answer
    • CIt stores the default dag_id for the DAG
    • DIt enables automatic XCom passing between tasks

    Why this is the answer

    `default_args` sets default values for operator-level arguments like `owner`, `retries`, and `depends_on_past` for all tasks.

  5. Question 16Multiple Select

    Which of the following are DAG-level parameters? (Select two)

    • AcatchupCorrect answer
    • Bretries
    • Cschedule_intervalCorrect answer
    • Demail_on_failure

    Why this is the answer

    `catchup` and `schedule_interval` are DAG-level parameters. Task-level parameters like `retries` belong in `default_args`.

  6. Question 17Interactive

    Review the DAG snippet in the code block. Why might the DAG not create any runs after the start_date?

    • AThe `catchup` parameter is set to False
    • BThe `start_date` is after the `schedule_interval` offset
    • CThe `schedule` parameter is set to `None`Correct answer
    • DThe `default_args` do not include `owner`

    Why this is the answer

    Setting `schedule=None` means the DAG is not automatically scheduled and will only run when triggered manually.

  7. Question 18Single Choice

    What is the primary role of the Airflow Scheduler?

    • AIt executes tasks by allocating resources on workers
    • BIt decides which tasks to run and when, then enqueues themCorrect answer
    • CIt stores task outputs and manages DAG file storage
    • DIt handles load balancing across multiple Airflow instances

    Why this is the answer

    The Scheduler determines task eligibility based on dependencies and schedule, then queues tasks for the Executor.

  8. Question 19Multiple Select

    Which of the following are valid executors in Apache Airflow? (Select two)

    • ASequentialExecutor
    • BCeleryExecutorCorrect answer
    • CKubernetesExecutorCorrect answer
    • DPythonExecutor

    Why this is the answer

    CeleryExecutor and KubernetesExecutor support distributed execution. SequentialExecutor is for debugging only.

  9. Question 20Interactive

    Examine the code and configuration description. What is the effect of setting `dag_concurrency=4` and `max_active_runs=2`?

    • AAt most 4 tasks can run across all runs of this DAG
    • BAt most 8 tasks can run simultaneously across all runsCorrect answer
    • CAt most 2 tasks can run in each DAG run
    • DAt most 4 tasks can run in each DAG run, and 2 runs in parallel

    Why this is the answer

    `dag_concurrency` limits tasks per run to 4, and `max_active_runs=2` allows up to 8 total tasks concurrently.

  10. Question 21Single Choice

    What is the correct syntax to set task B to run after task A using bitshift operators?

    • AA << B
    • BA >> BCorrect answer
    • CA >> B >> C
    • D[A, B] >> C

    Why this is the answer

    `A >> B` means A runs first, then B. This sets B as downstream of A.

  11. Question 22Multiple Select

    Which of the following statements about task dependencies are true? (Select two)

    • ABitshift operators can be applied to task groupsCorrect answer
    • BCircular dependencies are allowed if they form a cycle
    • C`set_upstream` is functionally identical to `<<`Correct answer
    • DDependencies must be set inside the `with` block before tasks are defined

    Why this is the answer

    Bitshift operators work with task groups, and `set_upstream` is equivalent to `<<`. Cycles cause parse errors.

Deployment and Security

4 questions in this domain

  1. Question 23Single Choice

    When Airflow looks for a connection, which backend is checked first by default?

    • AEnvironment variablesCorrect answer
    • BMetastoreDB
    • CHashiCorp Vault
    • DAWS Secrets Manager

    Why this is the answer

    The environment variable backend (AIRFLOW_CONN_* prefix) is checked first by default in Airflow's secrets resolution order.

  2. Question 24Multiple Select

    Which default Airflow roles have permission to trigger a DAG by default? (Select two)

    • AAdminCorrect answer
    • BOpCorrect answer
    • CUser
    • DViewer

    Why this is the answer

    Admin and Op roles have the can_create permission on DAGs by default, allowing them to trigger runs.

  3. Question 25Interactive

    Complete the code to fetch a connection URI securely inside a DAG instead of using os.environ.

    • ABaseHook.get_connectionCorrect answer
    • BVariable.get
    • Cos.environ.get
    • DConnection.get_uri

    Why this is the answer

    BaseHook.get_connection is the secure way to fetch connections, respecting secrets backend order.

  4. Question 26Single Choice

    What is required for Airflow Variables to be encrypted at rest?

    • ASetting a valid fernet_key in airflow.cfgCorrect answer
    • BUsing the Variable.get() method
    • CEnabling RBAC
    • DConfiguring a secrets backend

    Why this is the answer

    Encryption of Variables and Connections depends on a properly configured Fernet key in the Airflow configuration.

Operators and Hooks

11 questions in this domain

  1. Question 27Single Choice

    Which operator is designed to execute an arbitrary Python function within Airflow?

    • APythonOperatorCorrect answer
    • BBashOperator
    • CPostgresOperator
    • DDummyOperator

    Why this is the answer

    The PythonOperator is specifically designed to execute a Python callable. The BashOperator runs shell commands, PostgresOperator executes SQL, and DummyOperator does nothing.

  2. Question 28Multiple Select

    Select the operators that are built-in to Apache Airflow (as per the documentation).

    • APythonOperatorCorrect answer
    • BBashOperatorCorrect answer
    • CPostgresOperatorCorrect answer
    • DFileOperator

    Why this is the answer

    The three built-in operators discussed are PythonOperator, BashOperator, and PostgresOperator. FileOperator is not a standard Airflow operator.

  3. Question 29Interactive

    Examine the code snippet in the code block. Which import statement correctly imports the PythonOperator?

    • Afrom airflow.operators.python import PythonOperatorCorrect answer
    • Bfrom airflow.operators.bash import PythonOperator
    • Cfrom airflow.operators.dummy import PythonOperator
    • Dfrom airflow.operators.postgres import PythonOperator

    Why this is the answer

    PythonOperator resides in the airflow.operators.python module. The other options are incorrect because they reference different operator modules.

  4. Question 30Single Choice

    What is the default poke_interval for a sensor in Apache Airflow?

    • A30 seconds
    • B60 secondsCorrect answer
    • C90 seconds
    • D120 seconds

    Why this is the answer

    The default poke_interval is 60 seconds. This is a key fact about sensor configuration.

  5. Question 31Multiple Select

    Which parameters can be set on a sensor to control its maximum waiting time?

    • AtimeoutCorrect answer
    • Bexecution_timeoutCorrect answer
    • Cpoke_interval
    • Dretries

    Why this is the answer

    Both timeout (sensor-specific) and execution_timeout (task-level) can limit sensor duration. poke_interval controls frequency, not total time; retries control number of attempts after failure.

  6. Question 32Interactive

    Below is a BashOperator task definition. What command will be executed?

    • Aecho "2025-04-01"Correct answer
    • Becho "{{ ds }}"
    • Cecho 2025-04-01
    • Decho {{ ds }}

    Why this is the answer

    The template {{ ds }} is rendered as the date string (e.g., 2025-04-01) before execution, so the final command is echo \"2025-04-01\" (with quotes preserved). Option B is the raw template before rendering.

  7. Question 33Single Choice

    Which operator would you use to perform a SQL query on a PostgreSQL database?

    • APostgresOperatorCorrect answer
    • BPythonOperator
    • CBashOperator
    • DSqlOperator

    Why this is the answer

    PostgresOperator is the built-in operator specifically for executing SQL on PostgreSQL. SqlOperator is generic and not part of core Airflow.

  8. Question 34Multiple Select

    Which of the following are valid parameters for the PythonOperator?

    • Apython_callableCorrect answer
    • Bop_argsCorrect answer
    • Cop_kwargsCorrect answer
    • Dbash_command

    Why this is the answer

    PythonOperator accepts python_callable, op_args, and op_kwargs. bash_command is a parameter for BashOperator, not PythonOperator.

  9. Question 35Interactive

    The code shows a PostgresOperator. What does the sql parameter include?

    • ASELECT * FROM orders WHERE dt = '2025-04-01'Correct answer
    • BSELECT * FROM orders WHERE dt = 2025-04-01
    • CSELECT * FROM orders WHERE dt = '{{ ds }}'
    • DSELECT * FROM orders WHERE dt = ''{{ ds }}''

    Why this is the answer

    The sql parameter contains the template ''{{ ds }}'' which renders to the date string within single quotes (due to double single quotes). The final SQL becomes SELECT * FROM orders WHERE dt = '2025-04-01'.

  10. Question 36Single Choice

    What is the purpose of the `soft_fail` parameter in a sensor?

    • AThe task is marked as skipped.Correct answer
    • BThe task is marked as failed.
    • CThe task is automatically retried.
    • DThe task is marked as success.

    Why this is the answer

    With soft_fail=True, a sensor that times out is marked as 'skipped' (not failed), allowing downstream tasks to handle the absence appropriately.

  11. Question 37Multiple Select

    Which of the following are valid sensor modes in Apache Airflow?

    • ApokeCorrect answer
    • BrescheduleCorrect answer
    • Casync
    • Ddefer

    Why this is the answer

    The two modes are 'poke' (holds worker slot) and 'reschedule' (releases slot between pokes). 'async' and 'defer' are not valid mode values; deferrable is a separate parameter.

Testing and Quality Assurance

6 questions in this domain

  1. Question 38Single Choice

    Which method is used for lightweight unit testing of a DAG without requiring a database or scheduler?

    • Adag.run()
    • Bdag.test()Correct answer
    • Cairflow dags test
    • Dairflow tasks test

    Why this is the answer

    dag.test() runs the DAG inline without requiring a database or scheduler, making it ideal for unit tests.

  2. Question 39Multiple Select

    Which of the following are features of dag.test()?

    • AUses LocalExecutor by defaultCorrect answer
    • BUses a SQLite database that persists after test
    • CCleans up temporary database after executionCorrect answer
    • DRuns tasks sequentially in a single processCorrect answer

    Why this is the answer

    dag.test() uses LocalExecutor, runs tasks sequentially, and cleans up the temp database by default.

  3. Question 40Interactive

    Refer to the code block. Which pytest-airflow fixture is used to access the DagBag for testing?

    • Adag_bagCorrect answer
    • Bdag
    • Cdag_bag_list
    • Ddag_file

    Why this is the answer

    The dag_bag fixture from pytest-airflow loads all DAGs into a DagBag for validation.

  4. Question 41Single Choice

    Which executor does dag.test() use by default?

    • ASequentialExecutor
    • BLocalExecutorCorrect answer
    • CCeleryExecutor
    • DKubernetesExecutor

    Why this is the answer

    dag.test() uses LocalExecutor by default to run tasks in parallel subprocesses.

  5. Question 42Multiple Select

    Which of the following are true about airflow tasks test?

    • AIt runs a single task in the current processCorrect answer
    • BIt uses the scheduler to manage execution
    • CIt is useful for debugging task logicCorrect answer
    • DIt validates parallelism across tasks

    Why this is the answer

    airflow tasks test runs a single task inline without the scheduler, ideal for debugging.

  6. Question 43Interactive

    Given the DAG definition in the code block, what will be the state of the DAG run after calling dag.test() if the extract task raises an exception?

    • Asuccess
    • BfailedCorrect answer
    • Crunning
    • Dskipped

    Why this is the answer

    If a task fails without retry, the DAG run will be marked as failed.

Frequently asked questions

Everything about the Apache Airflow DAG Authoring question bank and how to use it.