{"record":{"id":"a98a8d743583a34a","repo":"lfnovo/open-notebook","slug":"error-fetching-default-models-str-e","errorCode":null,"errorMessage":"Error fetching default models: {str(e)}","messagePattern":"Error fetching default models: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/models.py","lineNumber":328,"sourceCode":"    try:\n        defaults = await DefaultModels.get_instance()\n\n        return DefaultModelsResponse(\n            default_chat_model=defaults.default_chat_model,  # type: ignore[attr-defined]\n            default_transformation_model=defaults.default_transformation_model,  # type: ignore[attr-defined]\n            large_context_model=defaults.large_context_model,  # type: ignore[attr-defined]\n            default_text_to_speech_model=defaults.default_text_to_speech_model,  # type: ignore[attr-defined]\n            default_speech_to_text_model=defaults.default_speech_to_text_model,  # type: ignore[attr-defined]\n            default_embedding_model=defaults.default_embedding_model,  # type: ignore[attr-defined]\n            default_tools_model=defaults.default_tools_model,  # type: ignore[attr-defined]\n        )\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error fetching default models: {str(e)}\")\n        raise HTTPException(\n            status_code=500, detail=f\"Error fetching default models: {str(e)}\"\n        )\n\n\n# Defaults the app cannot function without — they can be reassigned but\n# never cleared (the optional ones fall back to the chat default or are\n# simply skipped when unset).\nREQUIRED_DEFAULTS = {\"default_chat_model\", \"default_embedding_model\"}\n\n\n@router.put(\"/models/defaults\", response_model=DefaultModelsResponse)\nasync def update_default_models(defaults_data: DefaultModelsResponse):\n    \"\"\"Update default model assignments.\n\n    Partial-update semantics keyed on field PRESENCE, not value: a field\n    absent from the payload is left untouched, while an explicit null clears\n    the default (except required ones). `is not None` checks would silently\n    ignore a null sent to clear a default — the old value survived while the","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/models.py#L310-L346","documentation":"Generic 500 from GET /api/v1/models/defaults when reading the default-model assignments fails unexpectedly. Domain errors are re-raised; this branch wraps anything else (DB failure, deserialization of the defaults record).","triggerScenarios":"Calling GET /models/defaults when SurrealDB is unavailable or the stored defaults record is corrupted/has unknown fields.","commonSituations":"First run before migrations completed; DB restarted mid-request; schema drift after upgrade.","solutions":["Check API logs for 'Error fetching default models'","Ensure migrations ran on API startup (make api logs)","Restart the API/DB stack in order (database → api)","If the defaults record is corrupted, recreate it via the app UI or API"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"await fetch('/api/v1/health').then(r => { if (!r.ok) throw new Error('API unhealthy'); });","typeGuard":null,"tryCatchPattern":"try { const d = await api.getDefaultModels(); } catch (e) { if (e.status === 500) showRetry('Defaults unavailable'); }","preventionTips":["Start tiers in order: database → api","Wait for migrations on startup","Keep a fallback defaults view in the UI"],"tags":["models","defaults","http-500"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}