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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user