fix: identify route ordering issue - execute-stream must come before /{prompt_id}

ROOT CAUSE FOUND:
FastAPI matches routes in ORDER. The catch-all route /{prompt_id} at line 257
matches /execute-stream BEFORE the specific route at line 1448 can match.

Result: /api/prompts/execute-stream gets routed to get_prompt() which tries
to parse 'execute-stream' as a UUID, causing the error we've been seeing.

SOLUTION: Move /execute-stream route definition to BEFORE line 257 (before /{prompt_id})

This explains why require_auth_flexible was never called - the wrong endpoint
was being invoked entirely.
This commit is contained in:
Lars 2026-04-18 08:42:30 +02:00
parent a5aad0da7e
commit 35ba2d7fdb

View File

@ -254,6 +254,9 @@ def import_prompts(
}
# 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)):
"""Get single AI prompt by ID (UUID)."""
@ -1452,7 +1455,6 @@ async def execute_unified_prompt_stream(
save: bool = Query(False, description="Save result to ai_insights"),
session: dict = Depends(require_auth_flexible)
):
print("[EXECUTE_STREAM] Endpoint function called!") # DEBUG
"""
Execute a unified prompt with Server-Sent Events (SSE) streaming.
@ -1464,7 +1466,6 @@ async def execute_unified_prompt_stream(
Use this endpoint for long-running workflows (>30s) to avoid gateway timeouts.
"""
print(f"[EXECUTE_STREAM] session={repr(session)}") # DEBUG
profile_id = session['profile_id']
# Use default modules/timeframes (SSE doesn't support complex params)
@ -1596,7 +1597,7 @@ async def execute_unified_prompt_stream(
)
@router.post("/execute")
async def execute_unified_prompt(
prompt_slug: str = Query(..., description="Slug of prompt to execute"),
modules: Optional[dict] = None,