refactor: convert FastAPI dependencies to async#247
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the authentication/JWT FastAPI dependency chain to be async, enabling non-blocking JWKS/Auth0 network calls and aligning the test suite with the new async behavior.
Changes:
- Converted JWT verification + JWKS retrieval in
auth/validator.pyto async usinghttpx.AsyncClient. - Updated the session-user dependency in
auth/user_permissions.py(and downstream call sites) to await JWT verification. - Updated affected tests to use
AsyncMockand async test patterns.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
auth/validator.py |
Makes verify_jwt / JWKS fetch async and swaps cache locking to an async lock. |
auth/user_permissions.py |
Converts get_session_user dependency to async and awaits JWT verification. |
db/st_admin.py |
Awaits async verify_jwt during the Auth0 admin callback flow. |
tests/auth/test_auth_validator.py |
Migrates JWT/JWKS tests to async and updates concurrency test to asyncio tasks. |
tests/test_user.py |
Updates mocks for async JWT/session-user dependencies. |
tests/db/test_db_admin.py |
Updates mocks for async verify_jwt in admin callback tests. |
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.
Description
Convert some of our FastAPI dependencies to
async(particularly where we might do API calls) to minimize the chances requests get blocked waiting for API requests. This may not provide a huge speedup but is a relatively easy win (and could provide further benefit if we make our DB/Auth0 calls async in future).Changes
Checklist
How to Test Manually (if necessary)
Run
uv run pytest