Address review feedback: Address review feedback: Scaffold FastAPI backend project structure #17
@@ -28,11 +28,15 @@ class Base(DeclarativeBase):
|
||||
|
||||
|
||||
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:
|
||||
try:
|
||||
yield session
|
||||
await session.commit()
|
||||
except Exception:
|
||||
await session.rollback()
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user