Stop rebuilding the FAB app on every users and roles API call - #73104
Open
namanjain24-sudo wants to merge 1 commit into
Open
Stop rebuilding the FAB app on every users and roles API call#73104namanjain24-sudo wants to merge 1 commit into
namanjain24-sudo wants to merge 1 commit into
Conversation
The users, roles and permissions routes wrapped each request in the CLI helper get_application_builder(), which builds a new Flask app and AppBuilder every time and keeps each one alive through its cache. Use the auth manager's own Flask app instead, the same way the login routes do.
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 users, roles and permissions endpoints under
/auth/fab/v1wrapped every request inget_application_builder(), the helper written for the FAB CLI commands. It creates a new Flask app per call, so the@cacheon_return_appbuildernever hits and keeps every app alive. Each request also re-runsinit_appbuilder, which swaps the auth manager'sappbuilderfor the throwaway one and, with the defaultupdate_fab_perms, runs a fullsync_roles().These routes now use the auth manager's own Flask app through
_get_flask_app(), the same way the login routes already do. The CLI helper is unchanged.I ran a local
airflow api-server(sqlite, one worker) and sent 400 authenticated GETs to users and roles, 8 at a time:Postgres 16 showed the same pattern. The fab unit tests pass on sqlite and Postgres 16, and the API server also behaves correctly on MySQL 8.
One behaviour change:
sync_roles()no longer runs on every request, so a role created through the API without actions doesn't getcan_readonWebsiteuntil the next startup sync orairflow sync-perm. Roles created in the UI already work this way.closes: #72937
Was generative AI tooling used to co-author this PR?
Generated-by: a Gen-AI coding assistant, following the guidelines. I reviewed the change and ran the tests and the checks above locally.