invoke-ai/InvokeAI · info · HTTPException

str(e) (ValueError, relationship not found)

Error message

str(e) (ValueError, relationship not found)

What it means

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.

Source

Thrown at invokeai/app/api/routers/model_relationships.py:167

    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": {
                "application/json": {
                    "example": [
                        "ca562b14-995e-4a42-90c1-9528f1a5921d",
                        "cc0c2b8a-c62e-41d6-878e-cc74dde5ca8f",
                        "18ca7649-6a9e-47d5-bc17-41ab1e8cec81",
                        "7c12d1b2-0ef9-4bec-ba55-797b2d8f2ee1",
                        "c382eaa3-0e28-4ab0-9446-408667699aeb",
                        "71272e82-0e5f-46d5-bca9-9a61f4bd8a82",

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Treat 404 as success (already unlinked) and continue
  2. Fetch current related models first and only delete pairs that exist
  3. In cleanup scripts, swallow 404 but not other statuses

Example fix

// before
await api.removeRelationship({ model_key_1: a, model_key_2: b });
// after
try {
  await api.removeRelationship({ model_key_1: a, model_key_2: b });
} catch (e) {
  if (e.status !== 404) throw e; // already gone — fine
}
Defensive patterns

Strategy: try-catch

Validate before calling

const related = new Set(await api.getRelatedModels(key1));
if (!related.has(key2)) {
  console.log('nothing to unlink');
} else {
  await api.removeRelationship({ model_key_1: key1, model_key_2: key2 });
}

Try / catch

try {
  await api.removeRelationship({ model_key_1: a, model_key_2: b });
} catch (e) {
  if (e.status === 404) return; // already gone — idempotent
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Double-clicking 'unlink'; scripts removing relationships from stale caches; deleting relationships that were already removed by a model deletion cascade.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/dc83b2056eda710b. Report an issue: GitHub.