{"record":{"id":"e76982368297eec7","repo":"Comfy-Org/ComfyUI","slug":"asset-not-found-e76982","errorCode":"ASSET_NOT_FOUND","errorMessage":"AssetReference {reference_id} not found","messagePattern":"AssetReference (.+?) not found","errorType":"exception","errorClass":"ValueError","httpStatus":404,"severity":"error","filePath":"app/assets/database/queries/tags.py","lineNumber":135,"sourceCode":"            )\n        )\n        session.flush()\n\n    return SetTagsResult(added=sorted(to_add), removed=sorted(to_remove), total=sorted(desired))\n\n\ndef add_tags_to_reference(\n    session: Session,\n    reference_id: str,\n    tags: Sequence[str],\n    origin: str = \"manual\",\n    create_if_missing: bool = True,\n    reference_row: AssetReference | None = None,\n) -> AddTagsResult:\n    if not reference_row:\n        ref = session.get(AssetReference, reference_id)\n        if not ref:\n            raise ValueError(f\"AssetReference {reference_id} not found\")\n\n    norm = normalize_tags(tags)\n    if not norm:\n        total = get_reference_tags(session, reference_id=reference_id)\n        return AddTagsResult(added=[], already_present=[], total_tags=total)\n\n    if create_if_missing:\n        ensure_tags_exist(session, norm)\n\n    current = set(get_reference_tags(session, reference_id))\n\n    want = set(norm)\n    to_add = sorted(want - current)\n\n    if to_add:\n        with session.begin_nested() as nested:\n            try:\n                session.add_all(","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/app/assets/database/queries/tags.py#L117-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the reference exists and was committed before tagging.","In batch flows, pass reference_row when you already loaded it, and skip IDs that fail existence checks.","Catch ValueError and map to 404 ASSET_NOT_FOUND.","Filter client-supplied ID lists against current references before processing."],"exampleFix":"// before\nadd_tags_to_reference(session, reference_id=rid, tags=[\"a\"])\n\n// after\nref = session.get(AssetReference, rid)\nif ref is None:\n    skipped.append(rid)\nelse:\n    add_tags_to_reference(session, reference_id=rid, tags=[\"a\"], reference_row=ref)","handlingStrategy":"validation","validationCode":"ref = session.get(AssetReference, rid)\nif ref is not None:\n    add_tags_to_reference(session, rid, tags, reference_row=ref)","typeGuard":null,"tryCatchPattern":"try:\n    add_tags_to_reference(session, reference_id=rid, tags=tags)\nexcept ValueError as e:\n    raise HTTPException(status_code=404, detail=str(e))","preventionTips":["Pass reference_row when you already loaded the row — it skips the lookup and this error.","Filter ID lists against live references before bulk tagging."],"tags":["tags","assets","database","not-found","batch"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}