{"record":{"id":"89d606a73aba5199","repo":"invoke-ai/InvokeAI","slug":"style-preset-not-found","errorCode":null,"errorMessage":"Style preset not found","messagePattern":"Style preset not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"invokeai/app/api/routers/style_presets.py","lineNumber":72,"sourceCode":"    raise HTTPException(status_code=403, detail=\"Not authorized to access this style preset\")\n\n\ndef _assert_preset_write(record: StylePresetRecordDTO, current_user: TokenData) -> None:\n    \"\"\"Allow write access only for admin or owner. Defaults are immutable for non-admins.\"\"\"\n    if current_user.is_admin:\n        return\n    if record.type == PresetType.Default:\n        raise HTTPException(status_code=403, detail=\"Default style presets cannot be modified\")\n    if record.user_id == current_user.user_id:\n        return\n    raise HTTPException(status_code=403, detail=\"Not authorized to modify this style preset\")\n\n\ndef _load_record_or_404(style_preset_id: str) -> StylePresetRecordDTO:\n    try:\n        return ApiDependencies.invoker.services.style_preset_records.get(style_preset_id)\n    except StylePresetNotFoundError:\n        raise HTTPException(status_code=404, detail=\"Style preset not found\")\n\n\n@style_presets_router.get(\n    \"/i/{style_preset_id}\",\n    operation_id=\"get_style_preset\",\n    responses={\n        200: {\"model\": StylePresetRecordWithImage},\n    },\n)\ndef get_style_preset(\n    current_user: CurrentUserOrDefault,\n    style_preset_id: str = Path(description=\"The style preset to get\"),\n) -> StylePresetRecordWithImage:\n    \"\"\"Gets a style preset\"\"\"\n    record = _load_record_or_404(style_preset_id)\n    _assert_preset_read(record, current_user)\n    image = ApiDependencies.invoker.services.style_preset_image_files.get_url(style_preset_id)\n    return StylePresetRecordWithImage(image=image, **record.model_dump())","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/style_presets.py#L54-L90","documentation":"This HTTP 404 is raised by _load_record_or_404 when the style preset records service throws StylePresetNotFoundError, i.e. no preset exists with the given style_preset_id. It is shared by get, delete, and image-fetch endpoints so unknown IDs consistently return 404.","triggerScenarios":"GET/DELETE on /style_presets/i/{style_preset_id} with an ID that was deleted, never existed, or is mistyped.","commonSituations":"Preset deleted by another user/admin while a client still references it; stale ID stored in browser localStorage after a DB reset or fresh install; IDs from a different InvokeAI instance or an exported file from another deployment.","solutions":["List available presets (GET /style_presets/) and confirm the ID exists","Refresh client-side cached preset references; remove stale IDs from persisted state","Treat 404 as final for deleted presets — re-import the preset from its export file if still needed","Double-check the ID string for truncation or copying errors"],"exampleFix":"// before\nconst preset = await api.get(`/style_presets/i/${id}`); // throws if deleted\n// after\ntry {\n  const preset = await api.get(`/style_presets/i/${id}`);\n} catch (e) {\n  if (e.response?.status === 404) {\n    localStorage.removeItem('lastPresetId');\n    const all = await api.get('/style_presets/');\n    return all.data;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const all = (await api.get('/style_presets/')).data;\nif (!all.some(p => p.id === stylePresetId)) {\n  console.warn(`Preset ${stylePresetId} not in current preset list; it may be deleted`);\n}","typeGuard":"function isKnownPreset(presetList, id) {\n  return Array.isArray(presetList) && presetList.some(p => p?.id === id);\n}","tryCatchPattern":"try {\n  return (await api.get(`/style_presets/i/${id}`)).data;\n} catch (e) {\n  if (e.response?.status === 404) {\n    invalidateCachedPreset(id);\n    return null;\n  }\n  throw e;\n}","preventionTips":["Validate preset IDs against the list endpoint before get/delete calls","Clear persisted preset IDs after DB resets or switching instances","Treat 404 as permanent for deleted presets; re-import from export files if needed","Watch for concurrent deletions in multi-user setups"],"tags":["http-404","style-presets","not-found","invokeai"],"backgroundTag":"resource-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}