fix: move /execute-stream route BEFORE /{prompt_id} catch-all (FastAPI route ordering)
All checks were successful
Deploy Development / deploy (push) Successful in 58s
Build Test / pytest-backend (push) Successful in 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

Root cause: FastAPI matches routes in definition order. The /{prompt_id}
catch-all at line 257 was intercepting /execute-stream requests before
the specific route handler could match.

Fix: Moved execute-stream definition (with section header + imports)
to line 257, before the catch-all route (now at line 414).

This resolves the 'Connection to server lost' error in SSE streaming.
This commit is contained in:
Lars 2026-04-18 08:55:43 +02:00
parent 09d1b6f967
commit 879a3a58d7

View File

@ -254,6 +254,11 @@ def import_prompts(
}
# ══════════════════════════════════════════════════════════════════════════════
# UNIFIED PROMPT SYSTEM (Issue #28 Phase 2)
# ══════════════════════════════════════════════════════════════════════════════
from prompt_executor import execute_prompt_with_data
from models import UnifiedPromptCreate, UnifiedPromptUpdate
@ -403,9 +408,8 @@ async def execute_unified_prompt_stream(
"Connection": "keep-alive",
"X-Accel-Buffering": "no" # Disable nginx buffering
}
)
# NOTE: /execute-stream MUST be defined BEFORE /{prompt_id} to avoid route conflicts
# FastAPI matches routes in order, so specific routes must come before catch-all patterns
@router.get("/{prompt_id}")
def get_prompt(prompt_id: str, session: dict=Depends(require_auth)):
@ -1590,15 +1594,7 @@ def reset_prompt_to_default(prompt_id: str, session: dict=Depends(require_admin)
return {"ok": True}
# ══════════════════════════════════════════════════════════════════════════════
# UNIFIED PROMPT SYSTEM (Issue #28 Phase 2)
# ══════════════════════════════════════════════════════════════════════════════
from prompt_executor import execute_prompt_with_data
)
@router.post("/execute")
async def execute_unified_prompt(
prompt_slug: str = Query(..., description="Slug of prompt to execute"),
modules: Optional[dict] = None,