Skip to content

Conversation

@Lzzz666
Copy link
Contributor

@Lzzz666 Lzzz666 commented May 8, 2025

Related Issue

closes: #50348


This PR reintroduces the pre-import optimization for DAG parsing originally added in Airflow 2.6.0 (#30495) but missing in Airflow 3.0. It reduces DAG parsing time by importing common modules in the parent process before forking.

I referred to #30495 and made modifications to 'processor.py' based on its implementation. I understand the issue is currently assigned to @kevinhongzl, and I’m happy to collaborate or adjust direction depending on their progress.

Looking forward to feedback!


^ 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.

Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, just double checked with #30495 and left some nits.

@Lzzz666 Lzzz666 marked this pull request as draft May 10, 2025 04:09
@Lzzz666 Lzzz666 marked this pull request as ready for review May 10, 2025 07:01
Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for the change.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Also we might need to add a test for it

@eladkal eladkal added this to the Airflow 3.0.2 milestone May 12, 2025
@eladkal eladkal added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label May 12, 2025
@Lzzz666
Copy link
Contributor Author

Lzzz666 commented May 13, 2025

Also we might need to add a test for it

I’ll try adding a unit test for it.

@Lzzz666 Lzzz666 marked this pull request as draft May 14, 2025 14:05
@Lzzz666
Copy link
Contributor Author

Lzzz666 commented May 15, 2025

Hi, I attempted to refactor the logic into a function.

This refactoring provides the following benefits:

  1. Modularity: encapsulates the pre-import logic in a dedicated function
  2. Easier testing: allows the _pre_import_airflow_modules function to be unit-tested in isolation
  3. Improved readability: the function name clearly indicates its purpose

@Lzzz666 Lzzz666 marked this pull request as ready for review May 15, 2025 15:07
Copy link
Member

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

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

Thanks for the change.

Only a small nit on the test case naming: using test__pre_import_airflow_modules as a prefix would make it easier to identify the corresponding unit tests.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Left a few nits, but overall looks good

@Lee-W
Copy link
Member

Lee-W commented May 19, 2025

@jedcunningham @ephraimbuddy not sure whether it's something missed or intentionally removed. But it looks good to me. I'm planning on merging it early tomorrow

@Lee-W Lee-W self-requested a review May 19, 2025 14:47
@Lee-W
Copy link
Member

Lee-W commented May 19, 2025

I just revoke my approval.

@amoghrajesh
Copy link
Contributor

@Lzzz666 would you be able to take a look at the review comments on this PR?

Copy link
Contributor

@ephraimbuddy ephraimbuddy left a comment

Choose a reason for hiding this comment

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

LGTM

@Lzzz666 Lzzz666 requested a review from ashb June 27, 2025 02:02
@Lzzz666
Copy link
Contributor Author

Lzzz666 commented Jun 27, 2025

I tried to make an import error, then repaired the module, and the dag was retried and loaded successfully.

2025-06-27.7.48.40.mov

@Lzzz666 Lzzz666 requested a review from eladkal June 27, 2025 11:58
@uranusjr
Copy link
Member

uranusjr commented Jul 2, 2025

I’m going to merge this, let’s see what happens.

@uranusjr uranusjr merged commit d3bddfd into apache:main Jul 2, 2025
56 checks passed
@github-actions
Copy link

github-actions bot commented Jul 2, 2025

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
v3-0-test Commit Link

You can attempt to backport this manually by running:

cherry_picker d3bddfd v3-0-test

This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

@uranusjr
Copy link
Member

uranusjr commented Jul 2, 2025

@Lzzz666 Can you help with backporting this manually?

Lzzz666 added a commit to Lzzz666/airflow that referenced this pull request Jul 2, 2025
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Lzzz666 added a commit to Lzzz666/airflow that referenced this pull request Jul 2, 2025
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
kaxil pushed a commit to Lzzz666/airflow that referenced this pull request Jul 2, 2025
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
kaxil pushed a commit to Lzzz666/airflow that referenced this pull request Jul 2, 2025
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
@kaxil kaxil modified the milestones: Airflow 3.0.3, Airflow 3.0.4 Jul 2, 2025
@Lzzz666
Copy link
Contributor Author

Lzzz666 commented Jul 4, 2025

Manual backport done in #52698

Lee-W pushed a commit that referenced this pull request Jul 4, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 4, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 4, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 4, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 7, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 7, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 9, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 11, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
kaxil added a commit that referenced this pull request Jul 11, 2025
…0371) (#52698)

* Add back dag parsing pre-import optimization (#50371)

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>

* Apply suggestions from code review

---------

Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:DAG-processing backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect parsing_pre_import_modules in Airflow 3

10 participants