-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Refactor AuthManager from app.state to FastAPI dependency #57665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor AuthManager from app.state to FastAPI dependency #57665
Conversation
- Create new auth_manager.py module in common with AuthManagerDep - Update security.py to use AuthManagerDep instead of request.app.state.auth_manager - Update auth.py routes to use AuthManagerDep - Remove Request parameter where no longer needed - Follow the same dependency injection pattern as DagBag Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> Add unit tests for auth_manager dependency injection - Create test_auth_manager.py to test the new dependency - Verify auth_manager_from_app correctly retrieves from app.state - Test integration with existing test client fixture Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> Fix linting issues with ruff - Move BaseAuthManager import out of TYPE_CHECKING block - Fix import ordering in security.py - Remove unused pytest import from test - Remove trailing whitespace - Format code with ruff format Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com> Move auth_manager dependency to security.py module - Move auth_manager_from_app and AuthManagerDep from common/auth_manager.py to core_api/security.py - Update import in routes/public/auth.py to use security module - Move tests from common/test_auth_manager.py to core_api/test_security.py - Delete now-unused common/auth_manager.py and common/test_auth_manager.py - Import BaseAuthManager directly in security.py (not in TYPE_CHECKING) Co-authored-by: jason810496 <68415893+jason810496@users.noreply.github.com>
9998a38 to
16b534a
Compare
potiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - but I am not a FastAPI expert (yet :). ) It des make sense though following all what I've learned about dependencies in FastAPI - looks like breaking out with "old/classic ways of doing things in Flask".
|
So - second pair of eyes would be great :) |
vincbeck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
pierrejeambrun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Backport failed to create: v3-1-test. View the failure log Run details
You can attempt to backport this manually by running: cherry_picker 1242e07 v3-1-testThis should apply the commit to the v3-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continue |
- Create new auth_manager.py module in common with AuthManagerDep - Update security.py to use AuthManagerDep instead of request.app.state.auth_manager - Update auth.py routes to use AuthManagerDep - Remove Request parameter where no longer needed - Follow the same dependency injection pattern as DagBag Add unit tests for auth_manager dependency injection - Create test_auth_manager.py to test the new dependency - Verify auth_manager_from_app correctly retrieves from app.state - Test integration with existing test client fixture Fix linting issues with ruff - Move BaseAuthManager import out of TYPE_CHECKING block - Fix import ordering in security.py - Remove unused pytest import from test - Remove trailing whitespace - Format code with ruff format Move auth_manager dependency to security.py module - Move auth_manager_from_app and AuthManagerDep from common/auth_manager.py to core_api/security.py - Update import in routes/public/auth.py to use security module - Move tests from common/test_auth_manager.py to core_api/test_security.py - Delete now-unused common/auth_manager.py and common/test_auth_manager.py - Import BaseAuthManager directly in security.py (not in TYPE_CHECKING) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> (cherry picked from commit 1242e07)
|
Should it be backported? It is not a bug fix but more an optimization no? I am not against putting it in 3.1.X but the more we put things in patch releases, the more likely we can also add regressions |
Yeah, it's more like a optimization. I will close the backport PR #57814, we can reopen it again if anyone suggest to backport. |
|
Sounds good to me, updated the milestone to If that happens too often we can reconsider, maybe that will just be marginal. |
- Create new auth_manager.py module in common with AuthManagerDep - Update security.py to use AuthManagerDep instead of request.app.state.auth_manager - Update auth.py routes to use AuthManagerDep - Remove Request parameter where no longer needed - Follow the same dependency injection pattern as DagBag Add unit tests for auth_manager dependency injection - Create test_auth_manager.py to test the new dependency - Verify auth_manager_from_app correctly retrieves from app.state - Test integration with existing test client fixture Fix linting issues with ruff - Move BaseAuthManager import out of TYPE_CHECKING block - Fix import ordering in security.py - Remove unused pytest import from test - Remove trailing whitespace - Format code with ruff format Move auth_manager dependency to security.py module - Move auth_manager_from_app and AuthManagerDep from common/auth_manager.py to core_api/security.py - Update import in routes/public/auth.py to use security module - Move tests from common/test_auth_manager.py to core_api/test_security.py - Delete now-unused common/auth_manager.py and common/test_auth_manager.py - Import BaseAuthManager directly in security.py (not in TYPE_CHECKING) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
related: #50372
related comment: #50372 (comment)
Why
Replace
request.app.state.auth_managerwithAuthManagerDepfor better dependency tracking in Core API.