ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

feat(assets) Add asset file_path and display_name response fields

Open synap5e opened this issue 6 months ago â€ĸ 2 comments

What this does Adds 2 new optional fields to the asset system's Asset (and AssetCreated) schema:

  • file_path: The asset's path on disk (if it has one). Includes the models/{checkpoints,vae,...}/ or {input,output}/ prefix.
  • display_name: The asset's human-readable display name. Conventionally a the path within prefix, and what is displayed in the loading widget.

Motivation

In asset mode, the asset response's name field is overloaded. Depending on the asset's origin, the same field carries:

  • The ID for consumers
  • The rendered display label
  • (Sometimes) The file path they resolve to

In asset-mode, the frontend has ~10 widget and upload sites that read name or fall back to asset_hash to extract whichever role they need, with per-backend branching where the heuristics differ.

file_path exposes the full namespace-relative locator (models/checkpoints/flux/model.safetensors) as a dedicated field. display_name exposes the within-bucket path (flux/model.safetensors). The frontend can read what it needs without inferring from value shape or branching on backend.

Changes

  • Add file_path and display_name to the Asset output schema, inherited by AssetCreated.
  • Populate both fields in the shared asset response builder used by list, detail, upload/create, create-from-hash, and update responses.
  • Add path helpers that convert stored absolute reference paths into logical asset paths:
    • media assets: {input,output,temp}/...
    • model assets: models/<bucket>/...
  • Keep unknown or non-file-backed references nullable/omitted, matching existing exclude_none response behavior.
  • Document the new fields in OpenAPI.
  • Add focused tests for path computation, upload/list/detail response fields, and hash-only fast-path compatibility.

Verification

  • uv run --with-requirements requirements.txt --with-requirements tests-unit/requirements.txt pytest -q tests-unit/assets_test/services/test_path_utils.py tests-unit/assets_test/test_uploads.py::test_upload_response_includes_file_path_and_display_name tests-unit/assets_test/test_uploads.py::test_upload_fastpath_from_existing_hash_no_file tests-unit/assets_test/test_crud.py::test_metadata_filename_is_set_for_seed_asset_without_hash
  • uv run --with ruff ruff check app/assets/api/routes.py app/assets/api/schemas_out.py app/assets/services/path_utils.py tests-unit/assets_test/services/test_path_utils.py tests-unit/assets_test/test_uploads.py tests-unit/assets_test/test_crud.py

synap5e avatar May 20 '26 06:05 synap5e

Review Change Stack

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] â–ļī¸ Resume reviews
  • [ ] 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

â„šī¸ Recent review info
âš™ī¸ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2cb9ed9c-7dbf-4d72-aa9d-258dc2cb492e

đŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between 73ba8c6cbd8d11d6a0e22de39773540fba9f0442 and c533a881497d21bc062c84174fbf5cdd71382768.

📒 Files selected for processing (6)
  • app/assets/api/routes.py
  • app/assets/api/schemas_out.py
  • app/assets/services/path_utils.py
  • openapi.yaml
  • tests-unit/assets_test/services/test_path_utils.py
  • tests-unit/assets_test/test_uploads.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • app/assets/api/schemas_out.py
  • openapi.yaml
  • app/assets/api/routes.py
  • tests-unit/assets_test/services/test_path_utils.py
  • tests-unit/assets_test/test_uploads.py
  • app/assets/services/path_utils.py

📝 Walkthrough

Walkthrough

Adds AssetRoot typing and new path utilities (compute_asset_response_paths, compute_file_path, compute_display_name, get_asset_root_folder_name_and_filepath). Routes now import and use compute_asset_response_paths to populate Asset responses' file_path and display_name (or set them to None). Upload validation for "models" tags now uses is_comfy_model_folder_name. Asset schema and OpenAPI mark name deprecated and add nullable file_path and display_name. Unit and upload tests were added/updated to cover the new behavior.

đŸšĨ Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage âš ī¸ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding two new response fields (file_path and display_name) to the asset schema.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining motivation, implementation details, and examples of the new fields.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

âœī¸ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
âš”ī¸ Resolve merge conflicts
  • [ ] Resolve merge conflict in branch synap5e/feat/assets_add_file_path-BE-932

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 21 '26 04:05 coderabbitai[bot]

Heads up on the x-runtime: [cloud, local] tags here — the established convention in this file is that absence of x-runtime means both runtimes populate the field (i.e. it's the default). All 177 existing x-runtime usages in this file are [cloud] only — they mark cloud-only divergence from the default-both behavior. [cloud, local] is redundant with no tag and introduces a second pattern.

Two cleaner options:

  1. Drop the x-runtime: [cloud, local] tags entirely — absence carries the same meaning, and the existing 177 [cloud] usages stay self-consistent. This is what the convention currently calls for.
  2. Keep them and file a separate convention-change discussion if there's a reason explicit-over-implicit is preferable here — but that's a wider change that should be applied uniformly, not selectively.

(1) is the smaller change and avoids introducing dual conventions in the same file.

— [email protected]

mattmillerai avatar May 22 '26 01:05 mattmillerai