Comfy-Org/ComfyUI · error · ValueError

ASSET_NOT_FOUND

ASSET_NOT_FOUND

Error message

AssetReference {reference_id} not found

What it means

ValueError raised by resolve_asset_for_download when fetch_reference_and_asset returns no pair for the reference_id (not found, or filtered out for the given owner_id). This is the download-resolution entry point: it must locate both the reference row and its parent asset before picking a file path.

Source

Thrown at app/assets/services/asset_management.py:436

            or "application/octet-stream"
        )
    return DownloadResolutionResult(
        abs_path=abs_path,
        content_type=ctype,
        download_name=display_name,
    )


def resolve_asset_for_download(
    reference_id: str,
    owner_id: str = "",
) -> DownloadResolutionResult:
    with create_session() as session:
        pair = fetch_reference_and_asset(
            session, reference_id=reference_id, owner_id=owner_id
        )
        if not pair:
            raise ValueError(f"AssetReference {reference_id} not found")

        ref, asset = pair

        # For references with file_path, use that directly
        if ref.file_path and os.path.isfile(ref.file_path):
            abs_path = ref.file_path
        else:
            # For API-created refs without file_path, find a path from other refs
            refs = list_references_by_asset_id(session, asset_id=asset.id)
            abs_path = select_best_live_path(refs)
            if not abs_path:
                raise FileNotFoundError(
                    f"No live path for AssetReference {reference_id} "
                    f"(asset id={asset.id}, name={ref.name})"
                )

        # Capture ORM attributes before commit (commit expires loaded objects)
        ref_name = ref.name

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Confirm the ID is a reference ID (not an asset ID) and still exists in the reference list.
  2. Pass the correct owner_id for owner-scoped references instead of the empty default.
  3. Catch ValueError here and return 404 ASSET_NOT_FOUND with a refresh hint.
  4. Distinguish this from FileNotFoundError raised a few lines later when the reference exists but no live file path is found.

Example fix

// before
path = resolve_asset_for_download(reference_id=rid)

// after
try:
    path = resolve_asset_for_download(reference_id=rid, owner_id=uid)
except ValueError:
    raise HTTPException(status_code=404, detail=f"reference {rid} not found")
Defensive patterns

Strategy: try-catch

Validate before calling

ref = get_reference_by_id(session, reference_id=rid)
if ref is None or ref.deleted_at is not None:
    raise HTTPException(status_code=404, detail="reference not found")

Try / catch

try:
    path = resolve_asset_for_download(reference_id=rid, owner_id=uid)
except ValueError:
    raise HTTPException(status_code=404, detail=f"reference {rid} not found")
except FileNotFoundError:
    raise HTTPException(status_code=410, detail="no live file for reference")

Prevention

When it happens

Trigger: Calling the download endpoint with a reference_id that does not exist or is not visible to the supplied owner_id (owner_id defaults to empty string, which may exclude owner-owned rows depending on the fetch semantics).

Common situations: Expired download links rendered from stale pages; multi-user setups where owner_id is not propagated to the download request; frontend passing an asset id where a reference id is expected; references soft-deleted by mark-missing between page load and click.

Related errors


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