Skip to content

Commit aad9fe9

Browse files
committed
fix: Improve error handling and transaction cleanup in active_user fixture
Enhance user and transaction cleanup process in test fixture by: - Adding separate try-except blocks for transaction/vertex build deletion and user deletion - Adding debug logging for potential errors during cleanup - Ensuring proper session commits for each operation
1 parent a60b3e6 commit aad9fe9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/backend/tests/conftest.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ async def delete_transactions_by_flow_id(db: AsyncSession, flow_id: UUID):
135135
transactions = await db.exec(stmt)
136136
for transaction in transactions:
137137
await db.delete(transaction)
138-
await db.commit()
139138

140139

141140
async def _delete_transactions_and_vertex_builds(session, flows: list[Flow]):
@@ -435,12 +434,21 @@ async def active_user(client): # noqa: ARG001
435434
yield user
436435
# Clean up
437436
# Now cleanup transactions, vertex_build
438-
async with db_manager.with_session() as session:
439-
user = await session.get(User, user.id, options=[selectinload(User.flows)])
440-
await _delete_transactions_and_vertex_builds(session, user.flows)
441-
await session.delete(user)
437+
try:
438+
async with db_manager.with_session() as session:
439+
user = await session.get(User, user.id, options=[selectinload(User.flows)])
440+
await _delete_transactions_and_vertex_builds(session, user.flows)
441+
await session.commit()
442+
except Exception as e: # noqa: BLE001
443+
logger.debug(f"Error deleting transactions and vertex builds for user: {e}")
442444

443-
await session.commit()
445+
try:
446+
async with db_manager.with_session() as session:
447+
user = await session.get(User, user.id)
448+
await session.delete(user)
449+
await session.commit()
450+
except Exception as e: # noqa: BLE001
451+
logger.debug(f"Error deleting user: {e}")
444452

445453

446454
@pytest.fixture

0 commit comments

Comments
 (0)