Call init from auth managers only once#47869
Merged
Merged
Conversation
vincbeck
force-pushed
the
vincbeck/am_init
branch
from
March 17, 2025 21:02
5dd6d66 to
ab33cc7
Compare
bugraoz93
reviewed
Mar 17, 2025
vincbeck
force-pushed
the
vincbeck/am_init
branch
from
March 19, 2025 14:23
ab33cc7 to
3489ddc
Compare
vincbeck
force-pushed
the
vincbeck/am_init
branch
from
March 19, 2025 18:27
3489ddc to
f43beac
Compare
jedcunningham
approved these changes
Mar 19, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the auth manager initialization is only executed once per process, addressing the multiple invocations caused by the Flask application and FastAPI’s multi-worker environment. Key changes include:
- Adding file locking in SimpleAuthManager to restrict the init method to a single execution.
- Updating and adding tests to verify the correct handling of passwords and file content.
- Modifying FAB auth manager to use a dedicated method (init_flask_resources) for initialization in Flask applications.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/api_fastapi/auth/managers/simple/test_simple_auth_manager.py | Added tests covering password file reading/updating and filtering of user entries. |
| airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py | Introduced file locking via fcntl in the init method and refactored password retrieval logic. |
| providers/fab/src/airflow/providers/fab/www/extensions/init_appbuilder.py | Modified to call init_flask_resources instead of init for FAB auth manager. |
| providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py | Renamed init to init_flask_resources, aligning with the new initialization strategy. |
Comments suppressed due to low confidence (1)
airflow/api_fastapi/auth/managers/simple/simple_auth_manager.py:127
- Typo in the comment: 'User dot not exist in the file' should be corrected to 'User does not exist in the file'.
# User dot not exist in the file, adding it
Co-authored-by: Jed Cunningham <66968678+jedcunningham@users.noreply.github.com>
vincbeck
force-pushed
the
vincbeck/am_init
branch
from
March 20, 2025 14:01
f7ed25e to
1dd998c
Compare
agupta01
pushed a commit
to agupta01/airflow
that referenced
this pull request
Mar 21, 2025
shubham-pyc
pushed a commit
to shubham-pyc/airflow
that referenced
this pull request
Mar 22, 2025
nailo2c
pushed a commit
to nailo2c/airflow
that referenced
this pull request
Apr 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The method
initfrom auth managers is called multiples times for two reasons:initis also called in the Flask applications. This is only needed for fab auth manager. Thus, I created a method specificinit_flask_resourcesin FAB auth manager that I call in the Flask applicationsfastapispins up multiple workers (4 by default), thereforeinitis called 4 times. I updated the init function of simple auth manager to be called only once^ 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.rstor{issue_number}.significant.rst, in newsfragments.