{"record":{"id":"dc83b2056eda710b","repo":"invoke-ai/InvokeAI","slug":"str-e-valueerror-relationship-not-found","errorCode":null,"errorMessage":"str(e) (ValueError, relationship not found)","messagePattern":"str\\(e\\) \\(ValueError, relationship not found\\)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"info","filePath":"invokeai/app/api/routers/model_relationships.py","lineNumber":167,"sourceCode":"    current_user: AdminUserOrDefault,\n    req: ModelRelationshipCreateRequest = Body(..., description=\"The model keys to disconnect\"),\n) -> None:\n    \"\"\"\n    Removes a bidirectional relationship between two model keys.\n\n    - Raises 400 if attempting to unlink a model from itself.\n    - Raises 404 if the relationship was not found.\n    \"\"\"\n    if req.model_key_1 == req.model_key_2:\n        raise HTTPException(status_code=400, detail=\"Cannot unlink a model from itself.\")\n\n    try:\n        ApiDependencies.invoker.services.model_relationships.remove_model_relationship(\n            req.model_key_1,\n            req.model_key_2,\n        )\n    except ValueError as e:\n        raise HTTPException(status_code=404, detail=str(e))\n\n\n@model_relationships_router.post(\n    \"/batch\",\n    operation_id=\"get_related_models_batch\",\n    response_model=List[str],\n    responses={\n        200: {\n            \"description\": \"Related model keys retrieved successfully\",\n            \"content\": {\n                \"application/json\": {\n                    \"example\": [\n                        \"ca562b14-995e-4a42-90c1-9528f1a5921d\",\n                        \"cc0c2b8a-c62e-41d6-878e-cc74dde5ca8f\",\n                        \"18ca7649-6a9e-47d5-bc17-41ab1e8cec81\",\n                        \"7c12d1b2-0ef9-4bec-ba55-797b2d8f2ee1\",\n                        \"c382eaa3-0e28-4ab0-9446-408667699aeb\",\n                        \"71272e82-0e5f-46d5-bca9-9a61f4bd8a82\",","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/model_relationships.py#L149-L185","documentation":"HTTP 404 raised when the relationships service throws ValueError because no relationship exists between the two given keys. Deleting a non-existent bidirectional relationship is reported as not found.","triggerScenarios":"DELETE /api/v1/models/relationships with a pair that was never related, or that was already deleted — e.g. concurrent requests, or unlinking after the models were deleted.","commonSituations":"Double-clicking 'unlink'; scripts removing relationships from stale caches; deleting relationships that were already removed by a model deletion cascade.","solutions":["Treat 404 as success (already unlinked) and continue","Fetch current related models first and only delete pairs that exist","In cleanup scripts, swallow 404 but not other statuses"],"exampleFix":"// before\nawait api.removeRelationship({ model_key_1: a, model_key_2: b });\n// after\ntry {\n  await api.removeRelationship({ model_key_1: a, model_key_2: b });\n} catch (e) {\n  if (e.status !== 404) throw e; // already gone — fine\n}","handlingStrategy":"try-catch","validationCode":"const related = new Set(await api.getRelatedModels(key1));\nif (!related.has(key2)) {\n  console.log('nothing to unlink');\n} else {\n  await api.removeRelationship({ model_key_1: key1, model_key_2: key2 });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.removeRelationship({ model_key_1: a, model_key_2: b });\n} catch (e) {\n  if (e.status === 404) return; // already gone — idempotent\n  throw e;\n}","preventionTips":["Make unlink operations idempotent by swallowing 404","Refresh relationship caches before batch deletes","Handle model-deletion cascades that already removed relationships"],"tags":["http-404","not-found","model-relationships"],"backgroundTag":"resource-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}