Skip to content

Airflow dag.test() raises AirflowException: Cannot create DagRun for DAG because the dag is not serialized #56657

@tatiana

Description

@tatiana

Apache Airflow version

3.1.0

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

No response

What happened?

Airflow dag.test() stopped working in Airflow 3.1.

What you think should happen instead?

The command dag.test() should work as in Airlfow 3.0.

How to reproduce

Create this DAG file as example_bug.py:

from airflow import DAG
from airflow.decorators import dag, task

@dag(
    dag_id="simple_dag",
)
def simple_dag():
    """A simple DAG with two Python tasks."""

    @task
    def start():
        print("Starting the DAG...")
        return "Hello from start!"

    @task
    def end(message: str):
        print(f"Received message: {message}")
        print("Ending the DAG!")

    msg = start()
    end(msg)


dag = simple_dag()

if __name__ == "__main__":
    dag.test()

And run in a Python virtual environment with:

 python example_bug.py

Observe stacktrace similar to:

Traceback (most recent call last):
  File "/Users/tatiana.alchueyr/Code/astronomer-cosmos/example_bug.py", line 27, in <module>
    dag.test()
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/sdk/definitions/dag.py", line 1202, in test
    dr: DagRun = get_or_create_dagrun(
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/models/dagrun.py", line 2170, in get_or_create_dagrun
    dr = dag.create_dagrun(
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/utils/session.py", line 98, in wrapper
    return func(*args, **kwargs)
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/serialization/serialized_objects.py", line 3257, in create_dagrun
    orm_dagrun = _create_orm_dagrun(
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/utils/session.py", line 98, in wrapper
    return func(*args, **kwargs)
  File "/Users/tatiana.alchueyr/Library/Application Support/hatch/env/virtual/astronomer-cosmos/4lAAXoPP/tests.py3.10-3.1-1.10/lib/python3.10/site-packages/airflow/serialization/serialized_objects.py", line 2314, in _create_orm_dagrun
    raise AirflowException(f"Cannot create DagRun for DAG {dag.dag_id} because the dag is not serialized")
airflow.exceptions.AirflowException: Cannot create DagRun for DAG simple_dag because the dag is not serialized

Operating System

MacOS

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

This issue happens in the local environment, not in a deployed Airflow environment.

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions