Bird
Raised Fist0
Apache Airflowdevops~20 mins

ExternalTaskSensor for cross-DAG dependencies in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ExternalTaskSensor Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output when ExternalTaskSensor waits for a non-existent DAG?
You have an ExternalTaskSensor configured to wait for a task in a DAG that does not exist. What will happen when the sensor runs?
Apache Airflow
sensor = ExternalTaskSensor(
    task_id='wait_for_task',
    external_dag_id='non_existent_dag',
    external_task_id='some_task',
    mode='reschedule',
    timeout=30
)

sensor.execute(context={})
AThe sensor completes successfully without waiting because the external DAG is missing.
BThe sensor raises AirflowException immediately because the external DAG is not found.
CThe sensor waits until timeout and then raises AirflowSensorTimeout.
DThe sensor retries indefinitely without timeout.
Attempts:
2 left
💡 Hint
Think about how sensors behave when the external task or DAG is not yet available.
🧠 Conceptual
intermediate
1:30remaining
Which parameter controls the mode of ExternalTaskSensor to free worker slots while waiting?
In Airflow's ExternalTaskSensor, which parameter should you set to 'reschedule' mode to avoid occupying a worker slot while waiting for the external task?
Amode
Bsoft_fail
Ctimeout
Dpoke_interval
Attempts:
2 left
💡 Hint
This parameter changes how the sensor behaves during waiting periods.
🔀 Workflow
advanced
2:30remaining
Identify the correct ExternalTaskSensor configuration for cross-DAG dependency with execution date tolerance
You want to configure an ExternalTaskSensor to wait for a task in another DAG but allow a 10-minute delay in execution date matching. Which configuration is correct?
AExternalTaskSensor(external_dag_id='dag_b', external_task_id='task_b', execution_date_fn=lambda dt: dt - timedelta(minutes=10))
BExternalTaskSensor(external_dag_id='dag_b', external_task_id='task_b', execution_delta=timedelta(minutes=-10))
CExternalTaskSensor(external_dag_id='dag_b', external_task_id='task_b', execution_date_fn=lambda dt: dt + timedelta(minutes=10))
DExternalTaskSensor(external_dag_id='dag_b', external_task_id='task_b', execution_delta=timedelta(minutes=10))
Attempts:
2 left
💡 Hint
execution_delta shifts the execution date to look for the external task.
❓ Troubleshoot
advanced
2:00remaining
Why does ExternalTaskSensor fail with 'No active runs found' error?
You configured ExternalTaskSensor to wait for a task in another DAG, but it fails with 'No active runs found' error. What is the most likely cause?
AThe external DAG has no active DAG runs matching the execution date the sensor is waiting for.
BThe external task_id is misspelled in the sensor configuration.
CThe sensor's poke_interval is too short causing premature failure.
DThe sensor is running in 'poke' mode instead of 'reschedule' mode.
Attempts:
2 left
💡 Hint
Check the external DAG's run status and execution dates.
✅ Best Practice
expert
3:00remaining
What is the best practice to avoid deadlocks when using ExternalTaskSensor for cross-DAG dependencies?
When using ExternalTaskSensor to create dependencies between DAGs, what is the best practice to avoid deadlocks and ensure smooth execution?
AUse mode='poke' to keep the sensor active and avoid missing external task completion.
BSet timeout to None so the sensor waits indefinitely for the external task.
CUse execution_delta or execution_date_fn to align execution dates and avoid circular waits.
DTrigger all dependent DAGs manually to avoid sensor waits.
Attempts:
2 left
💡 Hint
Think about how execution dates affect cross-DAG dependencies and waiting.

Practice

(1/5)
1. What is the main purpose of the ExternalTaskSensor in Airflow?
easy
A. To wait for a task in another DAG to complete before proceeding
B. To trigger a DAG run manually
C. To schedule DAGs at specific intervals
D. To monitor system resource usage

Solution

  1. Step 1: Understand the role of ExternalTaskSensor

    The ExternalTaskSensor is designed to pause a task until a specified task in a different DAG finishes successfully.
  2. Step 2: Compare with other options

    Triggering DAGs, scheduling, and monitoring resources are handled by other components, not ExternalTaskSensor.
  3. Final Answer:

    To wait for a task in another DAG to complete before proceeding -> Option A
  4. Quick Check:

    ExternalTaskSensor waits for cross-DAG task completion [OK]
Hint: ExternalTaskSensor waits for tasks in other DAGs [OK]
Common Mistakes:
  • Confusing ExternalTaskSensor with DAG trigger
  • Thinking it schedules DAGs
  • Assuming it monitors system resources
2. Which of the following is the correct way to instantiate an ExternalTaskSensor to wait for task 'task_a' in DAG 'dag_1'?
easy
A. ExternalTaskSensor(task_id='wait_task', dag='dag_1', task='task_a')
B. ExternalTaskSensor(task_id='wait_task', dag_id='dag_1', task_id='task_a')
C. ExternalTaskSensor(task_id='wait_task', external_dag='dag_1', external_task='task_a')
D. ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a')

Solution

  1. Step 1: Identify correct parameter names

    The ExternalTaskSensor requires external_dag_id and external_task_id to specify the DAG and task it waits for.
  2. Step 2: Match parameters with options

    Only ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a') uses the correct parameter names and syntax.
  3. Final Answer:

    ExternalTaskSensor(task_id='wait_task', external_dag_id='dag_1', external_task_id='task_a') -> Option D
  4. Quick Check:

    Use external_dag_id and external_task_id parameters [OK]
Hint: Use external_dag_id and external_task_id parameters [OK]
Common Mistakes:
  • Using wrong parameter names like dag_id or external_dag
  • Confusing task_id with external_task_id
  • Omitting required parameters
3. Given this snippet in DAG 'dag_2':
wait_for_task = ExternalTaskSensor(
    task_id='wait_for_task_a',
    external_dag_id='dag_1',
    external_task_id='task_a',
    mode='reschedule',
    poke_interval=30
)

wait_for_task.execute(context={})

What happens if task_a in dag_1 has not completed yet?
medium
A. The sensor waits and retries every 30 seconds without blocking a worker slot
B. The sensor immediately fails with an error
C. The sensor completes successfully without waiting
D. The sensor blocks a worker slot and retries every 30 seconds

Solution

  1. Step 1: Understand mode='reschedule'

    In 'reschedule' mode, the sensor frees the worker slot between pokes, retrying after the poke_interval.
  2. Step 2: Analyze behavior when task not complete

    The sensor will keep checking every 30 seconds without blocking a worker slot until the external task finishes.
  3. Final Answer:

    The sensor waits and retries every 30 seconds without blocking a worker slot -> Option A
  4. Quick Check:

    mode='reschedule' frees worker slot during wait [OK]
Hint: mode='reschedule' frees worker slot during wait [OK]
Common Mistakes:
  • Confusing 'reschedule' with 'poke' mode
  • Assuming immediate failure if task incomplete
  • Thinking sensor completes without waiting
4. You wrote this ExternalTaskSensor:
wait_task = ExternalTaskSensor(
    task_id='wait_task',
    external_dag_id='dag_1',
    external_task_id='task_a',
    timeout=300
)

But the sensor never finishes even after task_a completes. What is the likely cause?
medium
A. The timeout is too high
B. The sensor's execution_date does not match the external task's execution date
C. The task_id is incorrect
D. The sensor is missing poke_interval

Solution

  1. Step 1: Understand execution_date matching

    ExternalTaskSensor waits for the external task with the same execution_date by default.
  2. Step 2: Identify mismatch issue

    If the sensor's execution_date differs from the external task's, it will wait forever even if the external task completed.
  3. Final Answer:

    The sensor's execution_date does not match the external task's execution date -> Option B
  4. Quick Check:

    Execution dates must match for ExternalTaskSensor to succeed [OK]
Hint: Check execution_date alignment between DAGs [OK]
Common Mistakes:
  • Assuming timeout controls waiting for task completion
  • Confusing task_id with external_task_id
  • Thinking poke_interval absence causes hang
5. You want to create a cross-DAG dependency where task_b in dag_2 waits for task_a in dag_1 to succeed, but only for the same execution date. Which configuration ensures this behavior and avoids deadlocks?
hard
A. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and execution_date_fn=lambda x: x - timedelta(days=1)
B. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and execution_date_fn=lambda x: x
C. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and default execution_date matching
D. Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and mode='poke' without execution_date control

Solution

  1. Step 1: Understand default execution_date behavior

    By default, ExternalTaskSensor waits for the external task with the same execution_date, ensuring correct cross-DAG sync.
  2. Step 2: Avoid execution_date shifts

    Using execution_date_fn to shift dates can cause deadlocks or missed dependencies.
  3. Step 3: Consider mode

    mode='poke' works but does not affect execution_date matching; default is fine here.
  4. Final Answer:

    Use ExternalTaskSensor with external_dag_id='dag_1', external_task_id='task_a', and default execution_date matching -> Option C
  5. Quick Check:

    Default execution_date matching avoids deadlocks [OK]
Hint: Default execution_date matching avoids deadlocks [OK]
Common Mistakes:
  • Shifting execution_date causing missed dependencies
  • Ignoring execution_date alignment
  • Misusing mode without fixing execution_date
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard