{"record":{"id":"ee0b634290bfea62","repo":"lfnovo/open-notebook","slug":"error-deleting-insight","errorCode":null,"errorMessage":"Error deleting insight","messagePattern":"Error deleting insight","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/insights.py","lineNumber":60,"sourceCode":"\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:\n        logger.error(f\"Error deleting insight {insight_id}: {str(e)}\")\n        raise HTTPException(status_code=500, detail=\"Error deleting insight\")\n\n\n@router.post(\"/insights/{insight_id}/save-as-note\", response_model=NoteResponse)\nasync def save_insight_as_note(insight_id: str, request: SaveAsNoteRequest):\n    \"\"\"Convert an insight to a note.\"\"\"\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        # Use the existing save_as_note method from the domain model\n        note = await insight.save_as_note(request.notebook_id)\n\n        return NoteResponse(\n            id=note.id or \"\",\n            title=note.title,\n            content=note.content,\n            note_type=note.note_type,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/insights.py#L42-L78","documentation":"Generic 500 from DELETE /api/insights/{insight_id} when insight.delete() raises an unexpected exception.","triggerScenarios":"DB outage/timeout during delete, driver-level permission error on the insight table, or record conflicts during concurrent deletes.","commonSituations":"SurrealDB restart mid-request, restricted DB credentials, concurrent modification of the same insight.","solutions":["Check the log 'Error deleting insight <id>' for the cause","Verify DB connectivity/permissions and retry","Handle 404-on-retry as success (already deleted)","Investigate driver errors for table-level constraints"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(2):\n    resp = await client.delete(f\"/api/insights/{insight_id}\")\n    if resp.status_code < 500 or resp.status_code == 404 or attempt:\n        break\n    await asyncio.sleep(1)","preventionTips":["Check server logs for the root exception","Ensure DB user has delete permission on insights table","Avoid issuing parallel deletes of the same insight"],"tags":["http-500","internal-error","insight","delete"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}