Comfy-Org/ComfyUI · error · ValueError

ASSET_NOT_FOUND

ASSET_NOT_FOUND

Error message

AssetReference {reference_id} not found

What it means

ValueError raised by add_tags_to_reference when reference_row is not supplied and session.get(AssetReference, reference_id) finds no row. Callers that already hold the reference row can pass reference_row to skip the lookup and this error entirely.

Source

Thrown at app/assets/database/queries/tags.py:135

            )
        )
        session.flush()

    return SetTagsResult(added=sorted(to_add), removed=sorted(to_remove), total=sorted(desired))


def add_tags_to_reference(
    session: Session,
    reference_id: str,
    tags: Sequence[str],
    origin: str = "manual",
    create_if_missing: bool = True,
    reference_row: AssetReference | None = None,
) -> AddTagsResult:
    if not reference_row:
        ref = session.get(AssetReference, reference_id)
        if not ref:
            raise ValueError(f"AssetReference {reference_id} not found")

    norm = normalize_tags(tags)
    if not norm:
        total = get_reference_tags(session, reference_id=reference_id)
        return AddTagsResult(added=[], already_present=[], total_tags=total)

    if create_if_missing:
        ensure_tags_exist(session, norm)

    current = set(get_reference_tags(session, reference_id))

    want = set(norm)
    to_add = sorted(want - current)

    if to_add:
        with session.begin_nested() as nested:
            try:
                session.add_all(

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Confirm the reference exists and was committed before tagging.
  2. In batch flows, pass reference_row when you already loaded it, and skip IDs that fail existence checks.
  3. Catch ValueError and map to 404 ASSET_NOT_FOUND.
  4. Filter client-supplied ID lists against current references before processing.

Example fix

// before
add_tags_to_reference(session, reference_id=rid, tags=["a"])

// after
ref = session.get(AssetReference, rid)
if ref is None:
    skipped.append(rid)
else:
    add_tags_to_reference(session, reference_id=rid, tags=["a"], reference_row=ref)
Defensive patterns

Strategy: validation

Validate before calling

ref = session.get(AssetReference, rid)
if ref is not None:
    add_tags_to_reference(session, rid, tags, reference_row=ref)

Try / catch

try:
    add_tags_to_reference(session, reference_id=rid, tags=tags)
except ValueError as e:
    raise HTTPException(status_code=404, detail=str(e))

Prevention

When it happens

Trigger: Tagging a reference_id that does not exist, without passing the optional reference_row parameter. Common from tagging endpoints that accept a raw ID, or batch tag operations over a list containing deleted references.

Common situations: Bulk tag operations where some IDs in the list were deleted since the client built it; tagging immediately after a failed ingest that rolled back the reference row; tests that tag before committing reference creation.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/e76982368297eec7. Report an issue: GitHub.