Skip to content

Dag test backcompat#2036

Closed
kaxil wants to merge 64 commits into
mainfrom
dag-test-backcompat
Closed

Dag test backcompat#2036
kaxil wants to merge 64 commits into
mainfrom
dag-test-backcompat

Conversation

@kaxil

@kaxil kaxil commented Oct 16, 2025

Copy link
Copy Markdown
Contributor

Description

Related Issue(s)

Breaking Change?

Checklist

  • I have made corresponding changes to the documentation (if required)
  • I have added tests that prove my fix is effective or that my feature works

apache-airflow==3.1.0b2 depends on Python>=3.10,<3.14
dbt has playing backnforth to changing the syntax to pass arguments to tests. Previously, dbt 1.10 and dbt Fusion were using the new syntax.
In one of the latest dbt 1.10 releases, it seems arguments syntax stopped working. We're therefore removing tests that were using this
…Run for DAG ... because the dag is not serialized

______________________ test_example_dag[basic_cosmos_dag] ______________________

session = <sqlalchemy.orm.session.Session object at 0x7f510a21d610>
dag_id = 'basic_cosmos_dag'

    @pytest.mark.skipif(
        AIRFLOW_VERSION in PARTIALLY_SUPPORTED_AIRFLOW_VERSIONS,
        reason="Airflow 2.9.0 and 2.9.1 have a breaking change in Dataset URIs, and Cosmos errors if `emit_datasets` is not False",
    )
    @pytest.mark.integration
    @pytest.mark.parametrize("dag_id", get_dag_ids())
    def test_example_dag(session, dag_id: str):
        if dag_id in KUBERNETES_DAGS:
            return
>       run_dag(dag_id)

tests/test_example_dags.py:147:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_example_dags.py:135: in run_dag
    test_utils.run_dag(dag)
tests/utils.py:31: in run_dag
    return test_dag(dag=dag, conn_file_path=conn_file_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/utils.py:61: in test_dag
    dr = new_test_dag(dag)
         ^^^^^^^^^^^^^^^^^
tests/utils.py:46: in new_test_dag
    dr = dag.test(logical_date=timezone.utcnow())
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../.local/share/hatch/env/virtual/astronomer-cosmos/Za_bFbg4/tests.py3.11-3.1-1.10/lib/python3.11/site-packages/airflow/sdk/definitions/dag.py:1202: in test
    dr: DagRun = get_or_create_dagrun(
../../../.local/share/hatch/env/virtual/astronomer-cosmos/Za_bFbg4/tests.py3.11-3.1-1.10/lib/python3.11/site-packages/airflow/models/dagrun.py:2170: in get_or_create_dagrun
    dr = dag.create_dagrun(
../../../.local/share/hatch/env/virtual/astronomer-cosmos/Za_bFbg4/tests.py3.11-3.1-1.10/lib/python3.11/site-packages/airflow/utils/session.py:98: in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
../../../.local/share/hatch/env/virtual/astronomer-cosmos/Za_bFbg4/tests.py3.11-3.1-1.10/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py:3257: in create_dagrun
    orm_dagrun = _create_orm_dagrun(
../../../.local/share/hatch/env/virtual/astronomer-cosmos/Za_bFbg4/tests.py3.11-3.1-1.10/lib/python3.11/site-packages/airflow/utils/session.py:98: in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @provide_session
    def _create_orm_dagrun(
        *,
        dag: SerializedDAG,
        run_id: str,
        logical_date: datetime.datetime | None,
        data_interval: DataInterval | None,
        run_after: datetime.datetime,
        start_date: datetime.datetime | None,
        conf: Any,
        state: DagRunState | None,
        run_type: DagRunType,
        creating_job_id: int | None,
        backfill_id: NonNegativeInt | None,
        triggered_by: DagRunTriggeredByType,
        triggering_user_name: str | None = None,
        session: Session = NEW_SESSION,
    ) -> DagRun:
        bundle_version = None
        if not dag.disable_bundle_versioning:
            bundle_version = session.scalar(
                select(DagModel.bundle_version).where(DagModel.dag_id == dag.dag_id),
            )
        dag_version = DagVersion.get_latest_version(dag.dag_id, session=session)
        if not dag_version:
>           raise AirflowException(f"Cannot create DagRun for DAG {dag.dag_id} because the dag is not serialized")
E           airflow.exceptions.AirflowException: Cannot create DagRun for DAG basic_cosmos_dag because the dag is not serialized
…Run for DAG ... because the dag is not serialized
@netlify

netlify Bot commented Oct 16, 2025

Copy link
Copy Markdown

Deploy Preview for sunny-pastelito-5ecb04 canceled.

Name Link
🔨 Latest commit dce0edf
🔍 Latest deploy log https://app.netlify.com/projects/sunny-pastelito-5ecb04/deploys/68f15d66cb4dea00093b4fce

kaxil added 3 commits October 16, 2025 22:02
Airflow 3.1+ requires DagVersion and DagModel records before calling
dag.test().

Used `sync_bag_to_db()` to create these records, matching
the approach used by Airflow's CLI `dag test` command.
@kaxil kaxil force-pushed the dag-test-backcompat branch from f5e1ba5 to dce0edf Compare October 16, 2025 21:02
@kaxil kaxil closed this Oct 16, 2025
tatiana pushed a commit that referenced this pull request Oct 17, 2025
Airflow 3.1+ requires DagVersion and DagModel records before calling
`dag.test()`.

[Example
failure:](https://github.com/astronomer/astronomer-cosmos/actions/runs/18523664806/job/52789291341#step:7:6713)

```
FAILED tests/test_example_dags.py::test_example_dag[example_cosmos_cleanup_dag] - airflow.exceptions.AirflowException: Cannot create DagRun for DAG example_cosmos_cleanup_dag because the dag is not serialized
FAILED tests/test_example_dags.py::test_example_dag[example_cosmos_dbt_build] - airflow.exceptions.AirflowException: Cannot create DagRun for DAG example_cosmos_dbt_build because the dag is not serialized
FAILED tests/test_example_dags.py::test_async_example_dag_without_setup_task - airflow.exceptions.AirflowException: Cannot create DagRun for DAG simple_dag_async because the dag is not serialized
```

Used `sync_bag_to_db()` to create these records, matching the approach
used by Airflow's CLI `dag test` command.

[Example
run](https://github.com/astronomer/astronomer-cosmos/actions/runs/18574691228/job/52957128514?pr=2036#step:7:1623)
on a different branch (branched off of @tatiana 's
[`af-31`](#1980):
[`dag-test-backcompat`](#2036))
which runs `dag.test` with Airflow 3.1 .
```
tests/test_example_dags.py::test_example_dag[cosmos_manifest_example] PASSED [ 61%]
tests/test_example_dags.py::test_example_dag[example_taskflow_project_config] PASSED [ 62%]
tests/test_example_dags.py::test_example_dag[example_multiple_parents_test] PASSED [ 62%]
tests/test_example_dags.py::test_example_dag[user_defined_profile] PASSED [ 63%]
tests/test_example_dags.py::test_example_dag[customized_cosmos_dag] PASSED [ 64%]
tests/test_example_dags.py::test_example_dag[basic_cosmos_dag] PASSED    [ 65%]
tests/test_example_dags.py::test_example_dag[cosmos_profile_mapping] PASSED [ 66%]
tests/test_example_dags.py::test_example_dag[basic_cosmos_task_group] PASSED [ 66%]
tests/test_example_dags.py::test_example_dag[example_duckdb_dag] PASSED  [ 67%]
tests/test_example_dags.py::test_example_dag[example_model_version] PASSED [ 68%]
tests/test_example_dags.py::test_example_dag[cosmos_callback_dag] PASSED [ 69%]
tests/test_example_dags.py::test_example_dag[example_operators] PASSED   [ 70%]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants