Skip to content

Conversation

@ephraimbuddy
Copy link
Contributor

@ephraimbuddy ephraimbuddy commented Oct 15, 2025

While dag test command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

Closes: #56657

@ephraimbuddy ephraimbuddy added this to the Airflow 3.1.1 milestone Oct 15, 2025
@ephraimbuddy ephraimbuddy added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Oct 15, 2025
Copy link
Contributor

@tatiana tatiana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ephraimbuddy Thanks a lot for working on this so quickly.
Would it be worth to update the PR description to mention it closes #56657?

@ephraimbuddy
Copy link
Contributor Author

@ephraimbuddy Thanks a lot for working on this so quickly. Would it be worth to update the PR description to mention it closes #56657?

Yes. Done. Thanks

@ephraimbuddy
Copy link
Contributor Author

I noticed the task is failing when executing:

2025-10-15T12:54:56.204021Z [info     ] [DAG TEST] starting task_id=test map_index=-1 [airflow.sdk.definitions.dag] loc=dag.py:1336
2025-10-15T12:54:56.204589Z [info     ] [DAG TEST] running task <TaskInstance: my_dag.test manual__2025-10-15T12:54:56.173999+00:00 [scheduled]> [airflow.sdk.definitions.dag] loc=dag.py:1339
2025-10-15T12:54:56.210513Z [error    ] [DAG TEST] Error running task <TaskInstance: my_dag.test manual__2025-10-15T12:54:56.173999+00:00 [queued]> [airflow.sdk.definitions.dag] loc=dag.py:1386
Traceback (most recent call last):
  File "/opt/airflow/task-sdk/src/airflow/sdk/definitions/dag.py", line 1349, in _run_task
    task_sdk_ti = TaskInstanceSDK(
  File "/usr/python/lib/python3.10/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for TaskInstance
dag_version_id
  UUID input should be a string, bytes or UUID object [type=uuid_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/uuid_type
2025-10-15T12:54:56.225062Z [info     ] [DAG TEST] end task task_id=test map_index=-1 [airflow.sdk.definitions.dag] loc=dag.py:1393
2025-10-15T12:54:56.228413Z [info     ] Marking run <DagRun my_dag @ 2025-10-14 00:00:00+00:00: manual__2025-10-15T12:54:56.173999+00:00, state:running, queued_at: None. run_type: manual> failed [airflow.models.dagrun.DagRun] loc=dagrun.py:1177
Dag run  in failure state
Dag information:my_dag Run id: manual__2025-10-15T12:54:56.173999+00:00 Run type: manual
Failed with message: task_failure
2025-10-15T12:54:56.236897Z [info     ] DagRun Finished: dag_id=my_dag, logical_date=2025-10-14 00:00:00+00:00, run_id=manual__2025-10-15T12:54:56.173999+00:00, run_start_date=2025-10-14 00:00:00+00:00, run_end_date=2025-10-15 12:54:56.228541+00:00, run_duration=132896.228541, state=failed, run_type=manual, data_interval_start=2025-10-14 00:00:00+00:00, data_interval_end=2025-10-14 00:00:00+00:00, [airflow.models.dagrun.DagRun] loc=dagrun.py:1280
DagRun failed

Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fundamental question: Should dag.test() create a temporary serialized DAG version like it was doing in one of the early 3.0.x version, or should it bypass the serialization requirement entirely?

@ephraimbuddy
Copy link
Contributor Author

Fundamental question: Should dag.test() create a temporary serialized DAG version like it was doing in one of the early 3.0.x version, or should it bypass the serialization requirement entirely?

dag.test uses an inmemory serialized dag now which I think it was doing in the earlier version. The reason it was working before was that there was no requirement to have serialized dag in db before creating a dagrun. Now we have that requirement.

The command option( airflow dag test) creates serialized dags in DB. And I think it's ok to create it. Helps us ensure we are testing with the real value. We can do the same for dag.test if it's prefered

@dstandish
Copy link
Contributor

Fundamental question: Should dag.test() create a temporary serialized DAG version like it was doing in one of the early 3.0.x version, or should it bypass the serialization requirement entirely?

dag.test uses an inmemory serialized dag now which I think it was doing in the earlier version. The reason it was working before was that there was no requirement to have serialized dag in db before creating a dagrun. Now we have that requirement.

The command option( airflow dag test) creates serialized dags in DB. And I think it's ok to create it. Helps us ensure we are testing with the real value. We can do the same for dag.test if it's prefered

yeah is there much downside to just creating it?

@kaxil
Copy link
Member

kaxil commented Oct 16, 2025

Fundamental question: Should dag.test() create a temporary serialized DAG version like it was doing in one of the early 3.0.x version, or should it bypass the serialization requirement entirely?

dag.test uses an inmemory serialized dag now which I think it was doing in the earlier version. The reason it was working before was that there was no requirement to have serialized dag in db before creating a dagrun. Now we have that requirement.
The command option( airflow dag test) creates serialized dags in DB. And I think it's ok to create it. Helps us ensure we are testing with the real value. We can do the same for dag.test if it's prefered

yeah is there much downside to just creating it?

Yeah I am in favor of making it consistent to airflow dag test . Which means change will be very isolated and not change other parts of the codebase

@ephraimbuddy ephraimbuddy force-pushed the dont-require-serdag-for-dagtest branch from 5d8bd17 to 5873cd6 Compare October 17, 2025 08:21
@ephraimbuddy ephraimbuddy changed the title Do not require serialized dag for dags test Ensure dag.test uses serialized dag for testing Oct 17, 2025
@ephraimbuddy ephraimbuddy requested a review from kaxil October 17, 2025 08:22
@ephraimbuddy
Copy link
Contributor Author

I have updated this PR to enable dag parsing in the dag.test method

@ephraimbuddy ephraimbuddy force-pushed the dont-require-serdag-for-dagtest branch 3 times, most recently from 829c6cf to d959325 Compare October 17, 2025 12:38
@ephraimbuddy ephraimbuddy force-pushed the dont-require-serdag-for-dagtest branch from d959325 to 5e9b466 Compare October 17, 2025 12:39
Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nitpicks -- lgtm otherwise

@ephraimbuddy ephraimbuddy removed the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Oct 17, 2025
@ephraimbuddy ephraimbuddy force-pushed the dont-require-serdag-for-dagtest branch 2 times, most recently from 957da39 to fcc70fc Compare October 17, 2025 15:46
While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed
@ephraimbuddy ephraimbuddy force-pushed the dont-require-serdag-for-dagtest branch from fcc70fc to 7f5e18c Compare October 18, 2025 06:51
@ephraimbuddy ephraimbuddy merged commit 6d977a9 into apache:main Oct 18, 2025
82 checks passed
@ephraimbuddy ephraimbuddy deleted the dont-require-serdag-for-dagtest branch October 18, 2025 13:45
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Oct 18, 2025
* Ensure dag.test uses serialized dag for testing

While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

* fixup! Ensure dag.test uses serialized dag for testing

* Update query to v2 and do backcompat for 3.1

* Remove backcompat

* Return previous behaviour with SerializedDag

(cherry picked from commit 6d977a9)
ephraimbuddy added a commit to astronomer/airflow that referenced this pull request Oct 18, 2025
potiuk pushed a commit that referenced this pull request Oct 18, 2025
…56820)

* Ensure dag.test uses serialized dag for testing (#56660)

* Ensure dag.test uses serialized dag for testing

While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

* fixup! Ensure dag.test uses serialized dag for testing

* Update query to v2 and do backcompat for 3.1

* Remove backcompat

* Return previous behaviour with SerializedDag

(cherry picked from commit 6d977a9)

* fixup! Ensure dag.test uses serialized dag for testing (#56660)
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
* Ensure dag.test uses serialized dag for testing

While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

* fixup! Ensure dag.test uses serialized dag for testing

* Update query to v2 and do backcompat for 3.1

* Remove backcompat

* Return previous behaviour with SerializedDag
nailo2c pushed a commit to nailo2c/airflow that referenced this pull request Oct 20, 2025
* Ensure dag.test uses serialized dag for testing

While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

* fixup! Ensure dag.test uses serialized dag for testing

* Update query to v2 and do backcompat for 3.1

* Remove backcompat

* Return previous behaviour with SerializedDag
TyrellHaywood pushed a commit to TyrellHaywood/airflow that referenced this pull request Oct 22, 2025
* Ensure dag.test uses serialized dag for testing

While `dag test` command uses serialized dag, dag.test was using
in-memory serialized dag making direct usage of dag.test method
resulting in error.

This PR fixes this and ensures dag.test parses dag if the dag is not
parsed

* fixup! Ensure dag.test uses serialized dag for testing

* Update query to v2 and do backcompat for 3.1

* Remove backcompat

* Return previous behaviour with SerializedDag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants