Skip to content

Conversation

@kaxil
Copy link
Member

@kaxil kaxil commented May 11, 2025

Previously, DagBag was injected via onlyFastAPI dependency as part of the refactor in #50372, but a new instance was created for each request. This change updates the dependency to resolve DagBag from app.state, ensuring it is only instantiated once at startup while keeping benefits of FastAPI dependency.


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

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label May 11, 2025
@kaxil kaxil added this to the Airflow 3.0.2 milestone May 11, 2025
@kaxil kaxil force-pushed the dagbag-singleton branch 2 times, most recently from c22860b to 8159898 Compare May 11, 2025 00:57
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.

LGTM, thanks! Initializing DagBag during FastAPI's lifespan event is a thread-safe and cleaner way to achieve a singleton pattern.

I had considered using airflow.utils.singleton.Singleton for this, but the current Singleton utility is not thread-safe. Adding a thread-level lock might introduce performance issues, especially if DagBag initialization takes a long time and blocks other threads.

@kaxil kaxil force-pushed the dagbag-singleton branch from 8159898 to 37d03e8 Compare May 11, 2025 08:09
@kaxil kaxil force-pushed the dagbag-singleton branch from 37d03e8 to cb93423 Compare May 11, 2025 10:13
Previously, DagBag was injected via onlyFastAPI dependency as part of the refactor in apache#50372 ,
but a new instance was created for each request. This change updates the dependency to resolve
DagBag from `app.state`, ensuring it is only instantiated once at startup while keeping benefits of FastAPI dependency.
@kaxil kaxil force-pushed the dagbag-singleton branch from cb93423 to 21a74b4 Compare May 12, 2025 08:21
@kaxil kaxil merged commit 3b49f9d into apache:main May 12, 2025
94 of 95 checks passed
@kaxil kaxil deleted the dagbag-singleton branch May 12, 2025 09:25
kaxil added a commit that referenced this pull request May 12, 2025
Previously, DagBag was injected via onlyFastAPI dependency as part of the refactor in #50372 ,
but a new instance was created for each request. This change updates the dependency to resolve
DagBag from `app.state`, ensuring it is only instantiated once at startup while keeping benefits of FastAPI dependency.

(cherry picked from commit 3b49f9d)
kaxil added a commit that referenced this pull request Jun 3, 2025
Previously, DagBag was injected via onlyFastAPI dependency as part of the refactor in #50372 ,
but a new instance was created for each request. This change updates the dependency to resolve
DagBag from `app.state`, ensuring it is only instantiated once at startup while keeping benefits of FastAPI dependency.

(cherry picked from commit 3b49f9d)
sanederchik pushed a commit to sanederchik/airflow that referenced this pull request Jun 7, 2025
Previously, DagBag was injected via onlyFastAPI dependency as part of the refactor in apache#50372 ,
but a new instance was created for each request. This change updates the dependency to resolve
DagBag from `app.state`, ensuring it is only instantiated once at startup while keeping benefits of FastAPI dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants