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.
This commit is contained in:
2026-06-22 20:19:28 +02:00
parent 262682cdf0
commit 18a5e2d6f0

View File

@@ -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(