Address review feedback: Address review feedback: Scaffold FastAPI backend project structure #17
@@ -28,11 +28,15 @@ class Base(DeclarativeBase):
|
|||||||
|
|
||||||
|
|
||||||
async def get_db() -> AsyncSession:
|
async def get_db() -> AsyncSession:
|
||||||
"""Dependency that yields an async database session."""
|
"""Dependency that yields an async database session.
|
||||||
|
|
||||||
|
Handlers are responsible for committing or rolling back their own
|
||||||
|
transactions. This avoids the double-commit problem where the
|
||||||
|
session is committed both here and in the handler.
|
||||||
|
"""
|
||||||
async with async_session_factory() as session:
|
async with async_session_factory() as session:
|
||||||
try:
|
try:
|
||||||
yield session
|
yield session
|
||||||
await session.commit()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user