invoke-ai/InvokeAI · warning · HTTPException
Cannot unlink a model from itself.
Error message
Cannot unlink a model from itself.
What it means
HTTP 400 raised by DELETE /models/relationships when model_key_1 equals model_key_2 in the request body. A model cannot be unlinked from itself; the endpoint validates this before touching the service layer.
Source
Thrown at invokeai/app/api/routers/model_relationships.py:159
404: {"description": "The relationship does not exist"},
422: {"description": "Validation error"},
500: {"description": "Internal server error"},
},
summary="Remove Model Relationship",
description="Removes a **bidirectional** relationship between two models. The relationship must already exist.",
)
def remove_model_relationship(
current_user: AdminUserOrDefault,
req: ModelRelationshipCreateRequest = Body(..., description="The model keys to disconnect"),
) -> None:
"""
Removes a bidirectional relationship between two model keys.
- Raises 400 if attempting to unlink a model from itself.
- Raises 404 if the relationship was not found.
"""
if req.model_key_1 == req.model_key_2:
raise HTTPException(status_code=400, detail="Cannot unlink a model from itself.")
try:
ApiDependencies.invoker.services.model_relationships.remove_model_relationship(
req.model_key_1,
req.model_key_2,
)
except ValueError as e:
raise HTTPException(status_code=404, detail=str(e))
@model_relationships_router.post(
"/batch",
operation_id="get_related_models_batch",
response_model=List[str],
responses={
200: {
"description": "Related model keys retrieved successfully",
"content": {View on GitHub (pinned to 0b6a024f2f)
Solutions
- Guard that model_key_1 !== model_key_2 before issuing the DELETE
- Filter out degenerate pairs when generating unlink requests from stored relationships
- Fix the UI/form sending one key in both fields
Example fix
// before
await api.removeRelationship({ model_key_1: k, model_key_2: k });
// after
if (k1 !== k2) await api.removeRelationship({ model_key_1: k1, model_key_2: k2 }); Defensive patterns
Strategy: validation
Validate before calling
if (req.model_key_1 === req.model_key_2) {
throw new Error('Cannot unlink a model from itself');
} Try / catch
try {
await api.removeRelationship(req);
} catch (e) {
if (e.status === 400 && e.body?.detail === 'Cannot unlink a model from itself.') throw new Error('self-pair in payload');
throw e;
} Prevention
- Filter degenerate (k,k) pairs out of unlink batches
- Derive unlink pairs from stored relationships, never from a single key
- Mirror the add-side self-pair guard in delete paths
When it happens
Trigger: DELETE /api/v1/models/relationships with identical keys in both fields of the request body — usually the same client bug that would have produced the self-relate 400 at add time.
Common situations: Symmetric cleanup scripts calling delete for every pair including degenerate pairs; stale client state passing one key twice.
Related errors
- Cannot relate a model to itself.
- No external provider config fields provided
- str(e)
- str(e) (ValueError from user service update, e.g. LastAdmini
- Current password is required to set a new password
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/a1e8b55b4553e698.
Report an issue: GitHub.