Replace 488 manual db.close() calls with middleware/dependency context manager #30

Closed
opened 2026-02-20 06:53:54 +00:00 by cal · 1 comment
Owner

488 `db.close()` calls across 31 files. Every endpoint must manually close on every code path. Any uncaught exception leaks a connection. Standard approach: middleware or dependency with try/finally.

Priority: high

488 \`db.close()\` calls across 31 files. Every endpoint must manually close on every code path. Any uncaught exception leaks a connection. Standard approach: middleware or dependency with try/finally. **Priority**: high
cal added the
bug
tech-debt
labels 2026-02-20 06:53:54 +00:00
cal added the
ai-working
label 2026-03-03 05:36:20 +00:00
Author
Owner

Fixed in PR #33: #33

Added a db_session_middleware to app/main.py that opens the connection at the start of each request and closes it in a try/finally block. Removed all 467 manual db.close() calls from the 30 router files in app/routers_v2/.

Fixed in PR #33: https://git.manticorum.com/cal/paper-dynasty-database/pulls/33 Added a `db_session_middleware` to `app/main.py` that opens the connection at the start of each request and closes it in a `try/finally` block. Removed all 467 manual `db.close()` calls from the 30 router files in `app/routers_v2/`.
cal added
ai-pr-opened
and removed
ai-working
labels 2026-03-03 05:37:55 +00:00
cal closed this issue 2026-03-10 18:26:28 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-database#30
No description provided.