átlagos kiegészítséek jó sok
This commit is contained in:
@@ -9,7 +9,8 @@ engine = create_async_engine(
|
||||
future=True,
|
||||
pool_size=30, # A robotok száma miatt
|
||||
max_overflow=20,
|
||||
pool_pre_ping=True
|
||||
pool_pre_ping=True,
|
||||
pool_reset_on_return='rollback'
|
||||
)
|
||||
|
||||
AsyncSessionLocal = async_sessionmaker(
|
||||
@@ -21,8 +22,20 @@ AsyncSessionLocal = async_sessionmaker(
|
||||
|
||||
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
async with AsyncSessionLocal() as session:
|
||||
# Start with a clean transaction state by rolling back any failed transaction
|
||||
try:
|
||||
await session.rollback()
|
||||
except Exception:
|
||||
# If rollback fails, it's probably because there's no transaction
|
||||
# This is fine, just continue
|
||||
pass
|
||||
|
||||
try:
|
||||
yield session
|
||||
# JAVÍTVA: Nincs automatikus commit! Az endpoint felelőssége.
|
||||
except Exception:
|
||||
# If any exception occurs, rollback the transaction
|
||||
await session.rollback()
|
||||
raise
|
||||
finally:
|
||||
# Ensure session is closed
|
||||
await session.close()
|
||||
Reference in New Issue
Block a user