Zie619/n8n-workflows · error · HTTPException

Workflow not found

Error message

Workflow not found

What it means

A 404 raised by GET /api/v2/workflows/{workflow_id} when _get_workflow_details returns falsy. Important caveat: the 404 HTTPException is raised INSIDE the try block, and the following 'except Exception' catches HTTPException too (it subclasses Exception), so the intended 404 is usually re-wrapped into a 500 with detail like '404: Workflow not found'. The 404 only survives if the re-wrap code path differs.

Source

Thrown at src/enhanced_api.py:161

            except Exception as e:
                raise HTTPException(status_code=500, detail=str(e))

        @self.app.get("/api/v2/workflows/{workflow_id}")
        async def get_workflow_enhanced(
            workflow_id: str,
            include_stats: bool = Query(True),
            include_ratings: bool = Query(True),
            include_related: bool = Query(True),
        ):
            """Get detailed workflow information"""
            try:
                workflow_data = self._get_workflow_details(
                    workflow_id, include_stats, include_ratings, include_related
                )

                if not workflow_data:
                    raise HTTPException(status_code=404, detail="Workflow not found")

                return workflow_data

            except Exception as e:
                raise HTTPException(status_code=500, detail=str(e))

        # Recommendation endpoints
        @self.app.post("/api/v2/recommendations")
        async def get_workflow_recommendations(request: WorkflowRecommendationRequest):
            """Get personalized workflow recommendations"""
            try:
                recommendations = self._get_recommendations(request)
                return {
                    "recommendations": recommendations,
                    "user_profile": request.dict(),
                    "timestamp": datetime.now().isoformat(),
                }

View on GitHub (pinned to 94007c1445)

Solutions

  1. Verify the id exists first via GET /api/v2/workflows (listing/search) and copy the exact id.
  2. Re-index the DB so ids in the index match what this endpoint serves.
  3. Fix the handler bug: re-raise HTTPException before the generic except (except HTTPException: raise / except Exception: ...).
  4. On the client, treat both 404 and a 500 containing 'Workflow not found' as not-found for now.

Example fix

# before
            try:
                workflow_data = self._get_workflow_details(...)
                if not workflow_data:
                    raise HTTPException(status_code=404, detail="Workflow not found")
                return workflow_data
            except Exception as e:
                raise HTTPException(status_code=500, detail=str(e))

# after
            try:
                workflow_data = self._get_workflow_details(...)
                if not workflow_data:
                    raise HTTPException(status_code=404, detail="Workflow not found")
                return workflow_data
            except HTTPException:
                raise
            except Exception as e:
                raise HTTPException(status_code=500, detail=str(e))
Defensive patterns

Strategy: validation

Validate before calling

known_ids = {w["id"] for w in client.get("/api/v2/workflows", params={"limit": 1000}).json()["workflows"]}

def workflow_exists(workflow_id: str) -> bool:
    return workflow_id in known_ids

Try / catch

try:
    resp = client.get(f"/api/v2/workflows/{workflow_id}")
    resp.raise_for_status()
    detail = resp.json()
except HTTPError as e:
    body = e.response.text
    if e.response.status_code == 404 or "Workflow not found" in body:
        raise KeyError(f"workflow {workflow_id!r} not found") from e
    raise

Prevention

When it happens

Trigger: Requesting a workflow id that does not exist in the DB (deleted, never indexed, wrong id format). Because of the over-broad except, the client often receives 500 instead of 404 for exactly the same condition.

Common situations: Stale workflow id from an old search index after reindexing changed ids; typo or URL-encoded id mismatch; fresh DB where nothing is indexed yet.

Related errors


AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15). Data as JSON: /api/errors/829a83d74ca615c2. Report an issue: GitHub.