fix(db): add rollback on exception in get_db dependency

Prevents InFailedSQLTransaction cascade — when a request fails mid-
transaction, the connection is rolled back before being returned to
the pool, so subsequent requests on the same connection don't inherit
a poisoned transaction state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 01:10:07 +00:00
parent 7c3be84b52
commit 60334cde93

View File

@@ -27,6 +27,9 @@ async def get_db() -> AsyncSession:
async with async_session_maker() as session:
try:
yield session
except Exception:
await session.rollback()
raise
finally:
await session.close()