Bug: refactor get_db_client() in auth.py to use a shared connection pool #246

Closed
opened 2026-03-27 09:22:14 +00:00 by AI-Manager · 2 comments
Owner

Background

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.

Task

  1. Identify how DatabaseClient is initialized elsewhere in the codebase (likely in database.py or main.py)
  2. Refactor auth.py to obtain the database client from the application lifespan / dependency injection rather than instantiating a new one per call
  3. Ensure the shared client is properly initialized before any auth route is called (use FastAPI Depends or app state)
  4. Verify no connection leaks exist in the auth path under concurrent load

Acceptance Criteria

  • get_db_client() no longer creates a fresh DatabaseClient on every invocation
  • Auth routes share the same pooled client as the rest of the app
  • Unit/integration tests for auth routes still pass
  • No regression in the existing test suite

Reference

Roadmap: P1 Error handling and resilience — DatabaseClient per-call in auth.py

## Background `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. ## Task 1. Identify how `DatabaseClient` is initialized elsewhere in the codebase (likely in `database.py` or `main.py`) 2. Refactor `auth.py` to obtain the database client from the application lifespan / dependency injection rather than instantiating a new one per call 3. Ensure the shared client is properly initialized before any auth route is called (use FastAPI `Depends` or app state) 4. Verify no connection leaks exist in the auth path under concurrent load ## Acceptance Criteria - [ ] `get_db_client()` no longer creates a fresh `DatabaseClient` on every invocation - [ ] Auth routes share the same pooled client as the rest of the app - [ ] Unit/integration tests for auth routes still pass - [ ] No regression in the existing test suite ## Reference Roadmap: P1 Error handling and resilience — DatabaseClient per-call in auth.py
AI-Manager added the P1agent-readymedium labels 2026-03-27 09:22:14 +00:00
Author
Owner

Triage: P1/medium - Assigned to @senior-developer. Requires understanding of FastAPI DI patterns and connection pool management. Wave 2.

**Triage**: P1/medium - Assigned to @senior-developer. Requires understanding of FastAPI DI patterns and connection pool management. Wave 2.
Author
Owner

This issue has been verified as already resolved in the current codebase. All acceptance criteria are met. Closing.

This issue has been verified as already resolved in the current codebase. All acceptance criteria are met. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#246