lfnovo/open-notebook · error · HTTPException

Error fetching insight

Error message

Error fetching insight

What it means

Generic 500 from GET /api/insights/{insight_id} when an unexpected exception occurs — commonly inside insight.get_source() while following the insight→source relationship.

Source

Thrown at api/routers/insights.py:40

        # Get source ID from the insight relationship
        source = await insight.get_source()

        return SourceInsightResponse(
            id=insight.id or "",
            source_id=source.id or "",
            insight_type=insight.insight_type,
            content=insight.content,
            created=insight.created.isoformat() if insight.created else None,
            updated=insight.updated.isoformat() if insight.updated else None,
        )
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error fetching insight {insight_id}: {str(e)}")
        raise HTTPException(status_code=500, detail="Error fetching insight")


@router.delete("/insights/{insight_id}")
async def delete_insight(insight_id: str):
    """Delete a specific insight."""
    try:
        insight = await SourceInsight.get(insight_id)
        if not insight:
            raise HTTPException(status_code=404, detail="Insight not found")

        await insight.delete()

        return {"message": "Insight deleted successfully"}
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check the log 'Error fetching insight <id>' for the traceback
  2. If the source was deleted leaving a dangling reference, delete/repair the orphaned insight
  3. Verify DB health and retry
  4. Fix migrations/relationships if get_source() consistently fails
Defensive patterns

Strategy: retry

Try / catch

try:
    return await client.get(f"/api/insights/{insight_id}")
except httpx.HTTPStatusError as e:
    if e.response.status_code >= 500:
        await asyncio.sleep(1)
        return await client.get(f"/api/insights/{insight_id}")
    raise

Prevention

When it happens

Trigger: SourceInsight.get succeeds but get_source() fails: dangling source reference (source deleted first), DB connectivity error, or response model serialization failure.

Common situations: Source deleted while its insights remained; SurrealDB restart mid-request; schema drift after migration breaking relationship traversal.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/3145ddf66b02967f. Report an issue: GitHub.