from contextlib import asynccontextmanager from .models import async_session @asynccontextmanager async def get_session(): """Provide a transactional scope around a series of operations.""" session = async_session() try: yield session await session.commit() except Exception: await session.rollback() raise finally: await session.close()