Skip to content

AttributeError: 'DAG' object has no attribute 'test' #51002

@stacymiller

Description

@stacymiller

Apache Airflow version

3.0.1

If "Other Airflow 2 version" selected, which one?

No response

What happened?

I took a sample TaskFlow API DAG from the documentation, installed all required packages and tried to call the test() method as mentioned in the documentation. This is what I usually do to test my DAGs, and on 2.* everything was OK. However, I received the following error message with Airflow 3.0.1:

Traceback (most recent call last):
  File "/data/test.py", line 62, in <module>
    dag.test()
AttributeError: 'DAG' object has no attribute 'test'

What you think should happen instead?

The DAG should be executed locally. This is the behaviour I observe in Airflow 2.10, and this was not expected to change.

How to reproduce

The file with DAG (both TaskFlow API and the classic API have this issue), assume it is called test.py:

# test.py for Airflow 3
import datetime
from airflow.sdk import dag
from airflow.providers.standard.operators.empty import EmptyOperator


@dag(start_date=datetime.datetime(2021, 1, 1), schedule="@daily")
def generate_dag():
    EmptyOperator(task_id="task")


my_dag = generate_dag()


if __name__ == '__main__':
    my_dag.test()

The command to run this code:

python test.py

The Dockerfile imitating the setup on the DAG author's machine:

FROM python:3.10-slim

COPY test.py test.py

RUN  python -m pip install "apache-airflow[celery]==3.0.1" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-3.0.1/constraints-3.9.txt"

RUN echo '#!/bin/bash\n\
airflow standalone > airflow.log 2>&1 &\n\
echo 'Wait until init...'\n\
sleep 15\n\
python test.py\n\
' > /entrypoint.sh && chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]

Output:

> docker build ./ -t test_airflow && docker run test_airflow
...
Wait until init...
Traceback (most recent call last):
  File "//test.py", line 31, in <module>
    my_dag.test()
AttributeError: 'DAG' object has no attribute 'test'

Operating System

macOS 15.4.1 locally, Debian in Docker

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

The setup that I use to validate that in Airflow 2 everything is working as expected:

# test.py for Airflow 2
import datetime

from airflow.decorators import dag
from airflow.operators.empty import EmptyOperator


@dag(start_date=datetime.datetime(2021, 1, 1), schedule="@daily")
def generate_dag():
    EmptyOperator(task_id="task")


my_dag = generate_dag()


if __name__ == '__main__':
    my_dag.test()
# Dockerfile for Airflow 2
FROM python:3.10-slim

COPY test.py test.py

RUN python -m pip install "apache-airflow[celery]==2.10.5" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.10.5/constraints-3.8.txt"

RUN echo '#!/bin/bash\n\
airflow standalone > airflow.log 2>&1 &\n\
echo 'Wait until init...'\n\
sleep 15\n\
python test.py\n\
' > /entrypoint.sh && chmod +x /entrypoint.sh

CMD ["/entrypoint.sh"]

Output:

> docker build ./ -t test_airflow && docker run test_airflow
...
[2025-05-23T12:01:20.538+0000] {dag.py:4410} INFO - [DAG TEST] end task task_id=task map_index=-1
[2025-05-23T12:01:20.539+0000] {dagrun.py:854} INFO - Marking run <DagRun generate_dag @ 2025-05-23 12:01:20.441239+00:00: manual__2025-05-23T12:01:20.441239+00:00, state:running, queued_at: None. externally triggered: False> successful
Dag run in success state
Dag run start:2025-05-23 12:01:20.441239+00:00 end:2025-05-23 12:01:20.539581+00:00
[2025-05-23T12:01:20.539+0000] {dagrun.py:905} INFO - DagRun Finished: dag_id=generate_dag, execution_date=2025-05-23 12:01:20.441239+00:00, run_id=manual__2025-05-23T12:01:20.441239+00:00, run_start_date=2025-05-23 12:01:20.441239+00:00, run_end_date=2025-05-23 12:01:20.539581+00:00, run_duration=0.098342, state=success, external_trigger=False, run_type=manual, data_interval_start=2025-05-22 00:00:00+00:00, data_interval_end=2025-05-23 00:00:00+00:00, dag_hash=None

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions