{"record":{"id":"24cbb50e1e6e2533","repo":"lfnovo/open-notebook","slug":"model-not-found","errorCode":null,"errorMessage":"Model not found","messagePattern":"Model not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"api/routers/models.py","lineNumber":274,"sourceCode":"        raise\n    except Exception as e:\n        logger.error(f\"Error creating model: {str(e)}\")\n        raise HTTPException(status_code=500, detail=f\"Error creating model: {str(e)}\")\n\n\n@router.delete(\"/models/{model_id}\")\nasync def delete_model(model_id: str):\n    \"\"\"Delete a model configuration.\"\"\"\n    try:\n        model = await Model.get(model_id)\n\n        await model.delete()\n\n        return {\"message\": \"Model deleted successfully\"}\n    except HTTPException:\n        raise\n    except NotFoundError:\n        raise HTTPException(status_code=404, detail=\"Model not found\")\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error deleting model {model_id}: {str(e)}\")\n        raise HTTPException(status_code=500, detail=f\"Error deleting model: {str(e)}\")\n\n\n@router.post(\"/models/{model_id}/test\", response_model=ModelTestResponse)\nasync def test_model(model_id: str):\n    \"\"\"Test if a specific model is correctly configured and functional.\"\"\"\n    try:\n        model = await Model.get(model_id)\n        if not model:\n            raise HTTPException(status_code=404, detail=\"Model not found\")\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/models.py#L256-L292","documentation":"404 from DELETE /api/v1/models/{model_id} when the repository raises NotFoundError, i.e. no model with that id exists (or it was already deleted). It is also the fallback mapping when Model.get inside delete fails to find the record.","triggerScenarios":"DELETE /models/{id} with a stale id, an id from another instance, or calling delete twice.","commonSituations":"UI holding a stale list after another tab/session deleted the model, or ids copied between environments.","solutions":["Refresh the model list and use current ids","Treat 404 on delete as success (idempotent delete) in the client","If the model should exist, verify you're pointing at the right API instance/database"],"exampleFix":"// before\nif (res.status !== 200) throw new Error('delete failed');\n// after\nif (res.status === 404) return; // already gone — treat as deleted\nif (!res.ok) throw new Error(await res.text());","handlingStrategy":"try-catch","validationCode":"const exists = (await api.getModels()).some(m => m.id === modelId);\nif (!exists) return; // nothing to delete","typeGuard":null,"tryCatchPattern":"try { await api.deleteModel(id); } catch (e) { if (e.status === 404) return; // idempotent success\n throw e; }","preventionTips":["Treat 404 on delete as success","Refresh lists after deletions","Never cache ids across environments"],"tags":["models","http-404","delete"],"backgroundTag":"resource-not-found","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}