{"record":{"id":"c5b23a91a48ea1c1","repo":"Zie619/n8n-workflows","slug":"error-searching-by-category-str-e","errorCode":null,"errorMessage":"Error searching by category: {str(e)}","messagePattern":"Error searching by category: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api_server.py","lineNumber":745,"sourceCode":"            except Exception as e:\n                print(\n                    f\"Error converting workflow {workflow.get('filename', 'unknown')}: {e}\"\n                )\n                continue\n\n        pages = (total + per_page - 1) // per_page\n\n        return SearchResponse(\n            workflows=workflow_summaries,\n            total=total,\n            page=page,\n            per_page=per_page,\n            pages=pages,\n            query=f\"category:{category}\",\n            filters={\"category\": category},\n        )\n    except Exception as e:\n        raise HTTPException(\n            status_code=500, detail=f\"Error searching by category: {str(e)}\"\n        )\n\n\n# Custom exception handler for better error responses\n@app.exception_handler(Exception)\nasync def global_exception_handler(request, exc):\n    return JSONResponse(\n        status_code=500, content={\"detail\": f\"Internal server error: {str(exc)}\"}\n    )\n\n\n# Mount static files AFTER all routes are defined\nstatic_dir = Path(\"static\")\nif static_dir.exists():\n    app.mount(\"/static\", StaticFiles(directory=\"static\"), name=\"static\")\n    print(f\"✅ Static files mounted from {static_dir.absolute()}\")\nelse:","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/api_server.py#L727-L763","documentation":"A generic 500 from GET /api/workflows/category/{category}. After computing workflow_summaries, total, and pages, any exception in the search/aggregation path is wrapped as 'Error searching by category: {str(e)}'. Causes live in the category search implementation called above the shown region (DB query, category normalization, or pagination math).","triggerScenarios":"GET /api/workflows/category/messaging (or any category slug) with a valid page/per_page while the underlying DB category index is missing or the category search helper raises — e.g. no such table/column, or a None row breaking summary construction. URL-encoded slashes or unknown categories typically flow through the search, not this 500.","commonSituations":"DB never indexed after a fresh deploy; category column renamed in a newer schema while the search query still uses the old name; very large per_page combined with a buggy row-mapping loop; SQLite lock during concurrent reindex.","solutions":["Reproduce with the exact category string and read the appended str(e) in the response body — it identifies the failing query/operation.","Run the reindex (POST /api/reindex with a valid admin token, or the CLI indexer) so category tables/rows exist.","Verify the category slug is one returned by GET /api/categories; use those exact values.","If the error persists, inspect the category-search helper above this handler for schema mismatches with your DB version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"valid_categories = set(client.get(\"/api/categories\").json()[\"categories\"])\n\ndef category_exists(category: str) -> bool:\n    return category in valid_categories","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.get(f\"/api/workflows/category/{category}\", params={\"page\": 1, \"per_page\": 20})\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Error searching by category\" in e.response.text:\n        # log detail (contains root cause) and surface an empty page to the UI\n        page_data = {\"workflows\": [], \"total\": 0, \"page\": 1, \"per_page\": 20, \"pages\": 0}\n    else:\n        raise","preventionTips":["Fetch /api/categories first and only query categories from that list.","URL-encode the category path segment to avoid ambiguous routing.","Keep per_page within 1..100 — out-of-range values already 422 before reaching this code."],"tags":["http-500","search","sqlite","fastapi","pagination"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}