From 18a5e2d6f0c41548c33cb5d6c2e9567a721a4e37 Mon Sep 17 00:00:00 2001 From: tegwick Date: Mon, 22 Jun 2026 20:19:28 +0200 Subject: [PATCH] fix(health): use injected session instead of global engine pool The /state/health probe now depends on get_session so pytest's dependency override routes through the test engine. Using engine.connect() directly caused asyncpg pool teardown failures (Event loop is closed) late in the full suite. --- api/routers/state.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/routers/state.py b/api/routers/state.py index 72c3a10..cd7fd89 100644 --- a/api/routers/state.py +++ b/api/routers/state.py @@ -7,7 +7,7 @@ from sqlalchemy import func, select, text from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import noload, selectinload -from api.database import get_session, engine +from api.database import get_session from api.flow_defs import assertion_result_to_dict, load_flow from api.models.capability_request import CapabilityRequest from api.models.contribution import Contribution, ContributionStatus, ContributionType @@ -1024,10 +1024,9 @@ async def get_next_steps(session: AsyncSession = Depends(get_session)) -> list[N @router.get("/health") -async def health_check() -> dict: +async def health_check(session: AsyncSession = Depends(get_session)) -> dict: try: - async with engine.connect() as conn: - await conn.execute(text("SELECT 1")) + await session.execute(text("SELECT 1")) return {"status": "ok", "db": "connected"} except Exception as exc: return JSONResponse(