fix: lock_tables acquires dedicated session to enforce RAII lock boundaries (#261)

This commit is contained in:
d3vyce
2026-05-02 15:44:19 -04:00
committed by d3vyce
parent 1a67da91e6
commit af4c57c293
4 changed files with 110 additions and 88 deletions
+15
View File
@@ -439,6 +439,21 @@ async def engine():
await engine.dispose()
@pytest.fixture(scope="function")
async def session_maker(engine):
"""Provide a session factory with tables created and dropped around the test."""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
factory = async_sessionmaker(engine, expire_on_commit=False)
try:
yield factory
finally:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
@pytest.fixture(scope="function")
async def db_session(engine):
"""Create a test database session with tables.