From 639394550573dcf98aa16e3949d3522111026d45 Mon Sep 17 00:00:00 2001 From: Jason Staack Date: Sun, 15 Mar 2026 06:31:21 -0500 Subject: [PATCH] fix(ci): filter cleanup tables to only those that exist Tables like invites/user_tenants only exist on saas-tiers branch. Query pg_tables to skip missing tables in TRUNCATE. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/tests/integration/conftest.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/tests/integration/conftest.py b/backend/tests/integration/conftest.py index eedefe5..11c91bf 100644 --- a/backend/tests/integration/conftest.py +++ b/backend/tests/integration/conftest.py @@ -165,15 +165,26 @@ async def admin_session(admin_engine) -> AsyncGenerator[AsyncSession, None]: Cleanup deletes all rows from test tables after the test. """ session = AsyncSession(admin_engine, expire_on_commit=False) - # TRUNCATE CASCADE reliably removes all data regardless of FK order - tables_csv = ", ".join(_CLEANUP_TABLES) - await session.execute(text(f"TRUNCATE {tables_csv} CASCADE")) + # TRUNCATE CASCADE reliably removes all data regardless of FK order. + # Filter to only tables that exist (some are saas-tiers only). + existing = await session.execute( + text( + "SELECT tablename FROM pg_tables " + "WHERE schemaname = 'public' AND tablename = ANY(:names)" + ), + {"names": _CLEANUP_TABLES}, + ) + existing_tables = [row[0] for row in existing.fetchall()] + if existing_tables: + tables_csv = ", ".join(existing_tables) + await session.execute(text(f"TRUNCATE {tables_csv} CASCADE")) await session.commit() try: yield session finally: - await session.execute(text(f"TRUNCATE {tables_csv} CASCADE")) - await session.commit() + if existing_tables: + await session.execute(text(f"TRUNCATE {tables_csv} CASCADE")) + await session.commit() await session.close()