Skip to content

Support running airflow dags test from local files - #50420

Merged
kaxil merged 2 commits into
apache:mainfrom
astronomer:dag-test-improvements
May 10, 2025
Merged

kaxil merged 2 commits into
apache:mainfrom
astronomer:dag-test-improvements

Conversation

@kaxil

@kaxil kaxil commented May 10, 2025

Copy link
Copy Markdown
Member

Currently, we can't run airflow dags test in isolation with a local dag file. We need to first run airflow dags reserialize, so DAGs are parsed and stored in DB, because the airflow dags test currently loads it from DB.

The change in this PR/commit allows testing DAGs from different sources:

  • Using bundle configuration (--bundle-name)
  • Using direct file path (--dagfile-path/-f)
  • Using default behavior (from DB)

This speeds up the process too since we don't have to load the entire DagBag to run a single file.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@kaxil
kaxil requested review from bugraoz93 and ephraimbuddy May 10, 2025 01:14
@kaxil kaxil added this to the Airflow 3.0.2 milestone May 10, 2025
@kaxil
kaxil requested a review from dstandish May 10, 2025 01:15
Currently, we can't run `airflow dags test` in isolation with a local dag file. We need to first run `airflow dags reserialize`, so DAGs are parsed and stored in DB, because the `airflow dags test` currently loads it from DB.

The change in this PR/commit allows testing DAGs from different sources:
- Using bundle configuration (`--bundle-name`)
- Using direct file path (`--dagfile-path`/`-f`)
- Using default behavior (from DB)

This speeds up the process too since we don't have to load the entire DagBag to run a single file.
@kaxil
kaxil force-pushed the dag-test-improvements branch from 6431b45 to f44180b Compare May 10, 2025 07:06
@dheerajturaga

dheerajturaga commented May 10, 2025 •

Copy link
Copy Markdown
Member

@kaxil , I fixed a similar issue in #49380

also reserialize only adds dags to the database, if a dag is broken/removed from dagbag reserialize does not remove it from the db.

the removal logic only seems to be in dag-processor

@kaxil

kaxil commented May 10, 2025

Copy link
Copy Markdown
Member Author

@kaxil , I fixed a similar issue in #49380

also reserialize only adds dags to the database, if a dag is broken/removed from dagbag reserialize does not remove it from the db.

the removal logic only seems to be in dag-processor

Yeah dag.test shouldn't need deserialization anyways

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice improvement

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
@kaxil
kaxil merged commit 7b0063b into apache:main May 10, 2025
@kaxil
kaxil deleted the dag-test-improvements branch May 10, 2025 13:01
kaxil added a commit that referenced this pull request May 12, 2025
Currently, we can't run `airflow dags test` in isolation with a local dag file. We need to first run `airflow dags reserialize`, so DAGs are parsed and stored in DB, because the `airflow dags test` currently loads it from DB.

The change in this PR/commit allows testing DAGs from different sources:
- Using bundle configuration (`--bundle-name`)
- Using direct file path (`--dagfile-path`/`-f`)
- Using default behavior (from DB)

This speeds up the process too since we don't have to load the entire DagBag to run a single file.

(cherry picked from commit 7b0063b)
kaxil added a commit that referenced this pull request Jun 3, 2025
Currently, we can't run `airflow dags test` in isolation with a local dag file. We need to first run `airflow dags reserialize`, so DAGs are parsed and stored in DB, because the `airflow dags test` currently loads it from DB.

The change in this PR/commit allows testing DAGs from different sources:
- Using bundle configuration (`--bundle-name`)
- Using direct file path (`--dagfile-path`/`-f`)
- Using default behavior (from DB)

This speeds up the process too since we don't have to load the entire DagBag to run a single file.

(cherry picked from commit 7b0063b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants