{"record":{"id":"5142b84648135916","repo":"lfnovo/open-notebook","slug":"insight-not-found","errorCode":null,"errorMessage":"Insight not found","messagePattern":"Insight not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"api/routers/insights.py","lineNumber":21,"sourceCode":"\nfrom api.models import NoteResponse, SaveAsNoteRequest, SourceInsightResponse\nfrom open_notebook.domain.notebook import SourceInsight\nfrom open_notebook.exceptions import (\n    InvalidInputError,\n    NotFoundError,\n    OpenNotebookError,\n)\n\nrouter = APIRouter()\n\n\n@router.get(\"/insights/{insight_id}\", response_model=SourceInsightResponse)\nasync def get_insight(insight_id: str):\n    \"\"\"Get a specific insight by ID.\"\"\"\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        # 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)}\")","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/insights.py#L3-L39","documentation":"HTTP 404 from GET /api/insights/{insight_id} when SourceInsight.get returns no insight for the id.","triggerScenarios":"Requesting a deleted/nonexistent insight, using a source id instead of an insight id, or an id from another environment.","commonSituations":"Insight deleted from the notebook UI while a client still holds its id; copy/paste of the wrong record id type; stale links/exports referencing removed insights.","solutions":["Verify the id is an insight id (not source/note id) from the listing endpoint","If deleted, regenerate or accept the 404 in the client","Confirm you're querying the same database/environment where the insight was created"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"insights = (await client.get(\"/api/insights\")).json()  # or per-source listing\nif insight_id not in {i[\"id\"] for i in insights}:\n    raise FileNotFoundError(insight_id)","typeGuard":"def is_insight_id(iid: str, insights: list[dict]) -> bool:\n    return iid in {i[\"id\"] for i in insights}","tryCatchPattern":"try:\n    insight = await client.get(f\"/api/insights/{insight_id}\")\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 404:\n        insight = None  # deleted upstream; drop from UI\n    else:\n        raise","preventionTips":["Refresh insight references after deletions in shared notebooks","Distinguish insight ids from source/note ids in client code","Handle 404 gracefully when rendering saved insight links"],"tags":["http-404","not-found","insight"],"backgroundTag":"resource-not-found","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}