diff --git a/app/core/db/__init__.py b/app/core/db/__init__.py index 7878b73..2212636 100644 --- a/app/core/db/__init__.py +++ b/app/core/db/__init__.py @@ -224,7 +224,7 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]: Used for normal API requests with tenant context set via RLS. Includes retry logic for transient connection errors. """ - from app.core.resilience import get_circuit, retry_db + from app.core.resilience import get_circuit, retry_db, _is_transient_db_error async def _get_session(): factory = get_session_factory() @@ -235,9 +235,11 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]: yield session await session.commit() await get_circuit("db").record_success() - except Exception: + except Exception as exc: await session.rollback() - await get_circuit("db").record_failure() + # Only record DB circuit failure for transient DB errors, not HTTP exceptions + if _is_transient_db_error(exc): + await get_circuit("db").record_failure() raise finally: await session.close()