airflow: dag.test() hangs with deferrable operators if DAG is paused

Apache Airflow version

2.5.0

What happened

When trying to use dag.test() with a DAG that uses a deferrable operator, the deferrable operator task is immediately marked as having run successfully, but the test then hangs in perpetuity:

docker exec f988cd7d2786 python dags/example_dag_basic.py

...

[2023-01-11 18:06:21,799] {taskinstance.py:1386} INFO - Pausing task as DEFERRED. dag_id=test_dag, task_id=wait_some_seconds_async, execution_date=20230111T180621, start_date=
[2023-01-11 18:06:21,804] {dag.py:3626} INFO - wait_some_seconds_async ran successfully!
[2023-01-11 18:06:21,804] {dag.py:3629} INFO - *****************************************************

What you think should happen instead

Either the test should run to completion, or the test should fail with a useful error message indicating that it failed because the DAG is paused.

How to reproduce

Create the below DAG, pause it, then run python <filename>.py.

from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta

from airflow.sensors.date_time import DateTimeSensorAsync

with DAG(
    "test_dag",
    default_args={
        "depends_on_past": False,
        "email": ["airflow@example.com"],
        "email_on_failure": False,
        "email_on_retry": False,
        "retries": 1,
    },
    description="A simple tutorial DAG",
    schedule="@daily",
    start_date=datetime(2021, 1, 1),
    catchup=False,
    tags=["example"],
) as dag:
    t0a = DateTimeSensorAsync(
        task_id="wait_some_seconds_async",
        target_time=datetime.now() + timedelta(seconds=5)
    )

Operating System

Debian GNU/Linux 11 (bullseye)

Versions of Apache Airflow Providers

n/a

Deployment

Astronomer

Deployment details

Locally via astro dev start with the Astro CLI. Also reproduced by another airflow user using Docker Compose.

Anything else

Also seeing the following error even when tasks (async or regular) run successfully with dag.test():

[2023-01-11 18:30:50,644] {dagrun.py:879} WARNING - Failed to record first_task_scheduling_delay metric:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/models/dagrun.py", line 867, in _emit_true_scheduling_delay_stats_for_finished_state
    first_start_date = ordered_tis_by_start_date[0].start_date
IndexError: list index out of range

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (12 by maintainers)

Most upvoted comments

Go ahead.