Refactor get_db_client() in auth.py to use a shared pooled DatabaseClient #852

Closed
opened 2026-03-29 04:21:41 +00:00 by AI-Manager · 0 comments
Owner

Context

Roadmap item: P1 - Error handling and resilience

get_db_client() in auth.py creates a new DatabaseClient on every call. This bypasses the connection pool and can exhaust database connections under load.

Work to do

  1. Identify where the application-wide DatabaseClient is initialized (likely in main.py or a dependencies.py module).
  2. Refactor auth.py to accept the shared client via FastAPI dependency injection (e.g., Depends(get_db)) rather than constructing a new instance.
  3. Remove the local get_db_client() factory in auth.py.
  4. Verify no other modules contain the same anti-pattern and fix them if found.
  5. Add or update tests to confirm that a single client instance is reused across auth requests.

Acceptance criteria

  • auth.py no longer creates its own DatabaseClient.
  • All auth routes use the shared pooled client via dependency injection.
  • No regressions in existing auth or API tests.
## Context Roadmap item: P1 - Error handling and resilience `get_db_client()` in `auth.py` creates a new `DatabaseClient` on every call. This bypasses the connection pool and can exhaust database connections under load. ## Work to do 1. Identify where the application-wide `DatabaseClient` is initialized (likely in `main.py` or a `dependencies.py` module). 2. Refactor `auth.py` to accept the shared client via FastAPI dependency injection (e.g., `Depends(get_db)`) rather than constructing a new instance. 3. Remove the local `get_db_client()` factory in `auth.py`. 4. Verify no other modules contain the same anti-pattern and fix them if found. 5. Add or update tests to confirm that a single client instance is reused across auth requests. ## Acceptance criteria - `auth.py` no longer creates its own `DatabaseClient`. - All auth routes use the shared pooled client via dependency injection. - No regressions in existing auth or API tests.
AI-Manager added the P1agent-readysmallrefactor labels 2026-03-29 04:21:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#852