multimeric opened a new issue, #60860:
URL: https://github.com/apache/airflow/issues/60860
### Apache Airflow version
3.1.6
### If "Other Airflow 3 version" selected, which one?
_No response_
### What happened?
```
Traceback (most recent call last):
File "/Users/milton.m/Programming/AirflowDagTest/main.py", line 27, in
<module>
my_dag_instance.test()
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/sdk/definitions/dag.py",
line 1245, in test
dr: DagRun = get_or_create_dagrun(
^^^^^^^^^^^^^^^^^^^^^
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/models/dagrun.py",
line 2175, in get_or_create_dagrun
dr = dag.create_dagrun(
^^^^^^^^^^^^^^^^^^
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/utils/session.py",
line 98, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/serialization/serialized_objects.py",
line 3342, in create_dagrun
orm_dagrun = _create_orm_dagrun(
^^^^^^^^^^^^^^^^^^^
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/utils/session.py",
line 98, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/Users/milton.m/Programming/AirflowDagTest/.venv/lib/python3.12/site-packages/airflow/serialization/serialized_objects.py",
line 2379, 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 my_dag
because the dag is not serialized
```
### What you think should happen instead?
`Dag.test` should appropriately serialize the DAG to prevent this issue. I
can actually see some logic for doing this already in the code, but it doesn't
seem to work:
https://github.com/apache/airflow/blob/d6a009b6dfa1802930f514a2429cc56f5b4c2f12/task-sdk/src/airflow/sdk/definitions/dag.py#L1233
### How to reproduce
Here's the minimal example I can come up with:
```python
import tempfile
import os
import pendulum
with tempfile.NamedTemporaryFile(suffix=".sqlite3", delete=False) as tmpfile:
conn_str = f"sqlite:///{tmpfile.name}"
os.environ["AIRFLOW__DATABASE__SQL_ALCHEMY_CONN"] = conn_str
from airflow.utils.db import upgradedb
upgradedb()
from airflow.sdk import task, dag
@dag(start_date=pendulum.datetime(2024, 1, 1))
def my_dag():
@task
def hello_task():
print("Hello, Airflow!")
hello_task()
my_dag_instance = my_dag()
my_dag_instance.test()
```
### Operating System
MacOS 15.6
### Versions of Apache Airflow Providers
None are relevant
### Deployment
Virtualenv installation
### Deployment details
A simple `pyproject.toml` with:
```toml
[project]
name = "airflowdagtest"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"apache-airflow>=3.1.6",
```
### Anything else?
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]