{"record":{"id":"016780d3d7dc40ce","repo":"Zie619/n8n-workflows","slug":"insights-error-str-e","errorCode":null,"errorMessage":"Insights error: {str(e)}","messagePattern":"Insights error: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/analytics_engine.py","lineNumber":384,"sourceCode":"        raise HTTPException(status_code=500, detail=f\"Analytics error: {str(e)}\")\n\n\n@analytics_app.get(\"/analytics/trends\")\nasync def get_trend_analysis(days: int = Query(30, ge=1, le=365)):\n    \"\"\"Get trend analysis for specified period.\"\"\"\n    try:\n        return analytics_engine.get_trend_analysis(days)\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Trend analysis error: {str(e)}\")\n\n\n@analytics_app.get(\"/analytics/insights\")\nasync def get_usage_insights():\n    \"\"\"Get usage insights and patterns.\"\"\"\n    try:\n        return analytics_engine.get_usage_insights()\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Insights error: {str(e)}\")\n\n\n@analytics_app.get(\"/analytics/dashboard\")\nasync def get_analytics_dashboard():\n    \"\"\"Get analytics dashboard HTML.\"\"\"\n    html_content = \"\"\"\n    <!DOCTYPE html>\n    <html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n        <title>N8N Analytics Dashboard</title>\n        <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n        <style>\n            * { margin: 0; padding: 0; box-sizing: border-box; }\n            body { \n                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n                background: #f8f9fa;","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/src/analytics_engine.py#L366-L402","documentation":"A generic 500 from GET /analytics/insights. The handler returns analytics_engine.get_usage_insights() directly; any exception becomes 'Insights error: {str(e)}'. Insight generation usually aggregates usage patterns, so it fails on missing/empty event data or unexpected field shapes in stored events.","triggerScenarios":"Calling /analytics/insights before any usage events exist, when the events table lacks columns the insights logic expects (KeyError), or when a JSON payload column contains data that fails to deserialize.","commonSituations":"New deployment with zero recorded usage; schema drift after upgrading analytics code without migrating stored events; corrupted JSON in event metadata columns.","solutions":["Read str(e) from the 500 detail — KeyError names the missing field; JSONDecodeError names the bad row.","Generate usage events (interact with the API a few times) so insights have input data.","Recreate or migrate the analytics DB to match the current insights schema.","If a single corrupted row is the cause, delete or repair rows with invalid JSON metadata."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    insights = client.get(\"/analytics/insights\").json()\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Insights error\" in e.response.text:\n        insights = {\"insights\": []}  # insights are advisory; UI works without them\n    else:\n        raise","preventionTips":["Treat insights as optional enrichment, never as a dependency of core flows.","Backfill a small set of usage events on fresh installs so insights code paths are exercised.","Add schema migrations for the events table so insights never meet unknown columns."],"tags":["http-500","analytics","insights","sqlite","data-quality"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}