{"record":{"id":"d67f5d1a13731ae4","repo":"Comfy-Org/ComfyUI","slug":"asset-not-found-d67f5d","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/services/asset_management.py","lineNumber":436,"sourceCode":"            or \"application/octet-stream\"\n        )\n    return DownloadResolutionResult(\n        abs_path=abs_path,\n        content_type=ctype,\n        download_name=display_name,\n    )\n\n\ndef resolve_asset_for_download(\n    reference_id: str,\n    owner_id: str = \"\",\n) -> DownloadResolutionResult:\n    with create_session() as session:\n        pair = fetch_reference_and_asset(\n            session, reference_id=reference_id, owner_id=owner_id\n        )\n        if not pair:\n            raise ValueError(f\"AssetReference {reference_id} not found\")\n\n        ref, asset = pair\n\n        # For references with file_path, use that directly\n        if ref.file_path and os.path.isfile(ref.file_path):\n            abs_path = ref.file_path\n        else:\n            # For API-created refs without file_path, find a path from other refs\n            refs = list_references_by_asset_id(session, asset_id=asset.id)\n            abs_path = select_best_live_path(refs)\n            if not abs_path:\n                raise FileNotFoundError(\n                    f\"No live path for AssetReference {reference_id} \"\n                    f\"(asset id={asset.id}, name={ref.name})\"\n                )\n\n        # Capture ORM attributes before commit (commit expires loaded objects)\n        ref_name = ref.name","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/app/assets/services/asset_management.py#L418-L454","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Confirm the ID is a reference ID (not an asset ID) and still exists in the reference list.","Pass the correct owner_id for owner-scoped references instead of the empty default.","Catch ValueError here and return 404 ASSET_NOT_FOUND with a refresh hint.","Distinguish this from FileNotFoundError raised a few lines later when the reference exists but no live file path is found."],"exampleFix":"// before\npath = resolve_asset_for_download(reference_id=rid)\n\n// after\ntry:\n    path = resolve_asset_for_download(reference_id=rid, owner_id=uid)\nexcept ValueError:\n    raise HTTPException(status_code=404, detail=f\"reference {rid} not found\")","handlingStrategy":"try-catch","validationCode":"ref = get_reference_by_id(session, reference_id=rid)\nif ref is None or ref.deleted_at is not None:\n    raise HTTPException(status_code=404, detail=\"reference not found\")","typeGuard":null,"tryCatchPattern":"try:\n    path = resolve_asset_for_download(reference_id=rid, owner_id=uid)\nexcept ValueError:\n    raise HTTPException(status_code=404, detail=f\"reference {rid} not found\")\nexcept FileNotFoundError:\n    raise HTTPException(status_code=410, detail=\"no live file for reference\")","preventionTips":["Always pass the real owner_id instead of the empty default on owner-scoped systems.","Distinguish ValueError (unknown reference) from FileNotFoundError (no live file) in handlers.","Refresh download links from a current reference list rather than caching them."],"tags":["assets","download","not-found","api"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}