feat: enhance database session management with commit and rollback; add user and deal API tests
Test / test (push) Successful in 14s
Test / test (push) Successful in 14s
This commit is contained in:
@@ -14,4 +14,9 @@ AsyncSessionMaker = async_sessionmaker(bind=engine, expire_on_commit=False)
|
||||
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
"""Yield an async database session for request scope."""
|
||||
async with AsyncSessionMaker() as session:
|
||||
yield session
|
||||
try:
|
||||
yield session
|
||||
await session.commit()
|
||||
except Exception: # pragma: no cover - defensive cleanup
|
||||
await session.rollback()
|
||||
raise
|
||||
|
||||
@@ -108,6 +108,7 @@ class DealRepository:
|
||||
if hasattr(deal, field):
|
||||
setattr(deal, field, value)
|
||||
await self._session.flush()
|
||||
await self._session.refresh(deal)
|
||||
return deal
|
||||
|
||||
def _apply_filters(
|
||||
|
||||
Reference in New Issue
Block a user