{"record":{"id":"3145ddf66b02967f","repo":"lfnovo/open-notebook","slug":"error-fetching-insight","errorCode":null,"errorMessage":"Error fetching insight","messagePattern":"Error fetching insight","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/insights.py","lineNumber":40,"sourceCode":"\n        # Get source ID from the insight relationship\n        source = await insight.get_source()\n\n        return SourceInsightResponse(\n            id=insight.id or \"\",\n            source_id=source.id or \"\",\n            insight_type=insight.insight_type,\n            content=insight.content,\n            created=insight.created.isoformat() if insight.created else None,\n            updated=insight.updated.isoformat() if insight.updated else None,\n        )\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error fetching insight {insight_id}: {str(e)}\")\n        raise HTTPException(status_code=500, detail=\"Error fetching insight\")\n\n\n@router.delete(\"/insights/{insight_id}\")\nasync def delete_insight(insight_id: str):\n    \"\"\"Delete a specific insight.\"\"\"\n    try:\n        insight = await SourceInsight.get(insight_id)\n        if not insight:\n            raise HTTPException(status_code=404, detail=\"Insight not found\")\n\n        await insight.delete()\n\n        return {\"message\": \"Insight deleted successfully\"}\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/insights.py#L22-L58","documentation":"Generic 500 from GET /api/insights/{insight_id} when an unexpected exception occurs — commonly inside insight.get_source() while following the insight→source relationship.","triggerScenarios":"SourceInsight.get succeeds but get_source() fails: dangling source reference (source deleted first), DB connectivity error, or response model serialization failure.","commonSituations":"Source deleted while its insights remained; SurrealDB restart mid-request; schema drift after migration breaking relationship traversal.","solutions":["Check the log 'Error fetching insight <id>' for the traceback","If the source was deleted leaving a dangling reference, delete/repair the orphaned insight","Verify DB health and retry","Fix migrations/relationships if get_source() consistently fails"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    return await client.get(f\"/api/insights/{insight_id}\")\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code >= 500:\n        await asyncio.sleep(1)\n        return await client.get(f\"/api/insights/{insight_id}\")\n    raise","preventionTips":["Delete insights when deleting their source to avoid dangling relationships","Watch API logs — get_source() failures are visible with tracebacks","Keep migrations consistent so insight→source edges stay valid"],"tags":["http-500","internal-error","insight","dangling-reference","database"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}