Spaces:
Runtime error
Runtime error
File size: 398 Bytes
339f372 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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() |