mirror of
https://github.com/Comfy-Org/ComfyUI.git
synced 2026-08-05 18:05:08 +08:00
fix(assets): don't hit uninitialized database from /view hash resolution
With --disable-assets (or after a database init failure) init_db() never runs and Session stays None, but /view?filename=blake3:<hash> still called resolve_hash_to_path(), raising TypeError and returning a 500. Workflows saved while assets were enabled trigger this on preview render in disabled mode. Gate the hash branch on live assets availability and return 404, which also fixes the pre-existing 500 on the degraded path. Also copy output_ui in the disabled enrichment fast path so the 'returns a new dict' contract holds in both modes.
This commit is contained in:
@@ -13,7 +13,7 @@ def enrich_output_with_assets(output_ui: dict) -> dict:
|
||||
"""
|
||||
from comfy.cli_args import args
|
||||
if args.disable_assets:
|
||||
return output_ui
|
||||
return dict(output_ui)
|
||||
|
||||
import folder_paths
|
||||
from app.assets.services.ingest import register_file_in_place, DependencyMissingError
|
||||
|
||||
@@ -44,7 +44,7 @@ from comfyui_version import __version__
|
||||
from app.frontend_management import FrontendManager, parse_version
|
||||
from comfy_api.internal import _ComfyNodeInternal
|
||||
from app.assets.seeder import asset_seeder
|
||||
from app.assets.api.routes import register_assets_routes
|
||||
from app.assets.api.routes import register_assets_routes, assets_enabled
|
||||
from app.assets.services.ingest import register_file_in_place
|
||||
from app.assets.services.path_utils import get_known_subfolder_tags
|
||||
from app.assets.services.asset_management import resolve_hash_to_path
|
||||
@@ -523,6 +523,12 @@ class PromptServer():
|
||||
# node preview, it constructs /view?filename=<asset_hash>, so this
|
||||
# endpoint must resolve blake3 hashes to their on-disk file paths.
|
||||
if filename.startswith("blake3:"):
|
||||
# Hash resolution requires the asset database. When assets
|
||||
# are disabled (--disable-assets) or unavailable (DB init
|
||||
# failure) the database was never initialized, so treat the
|
||||
# hash as unresolvable rather than erroring on a session.
|
||||
if not assets_enabled():
|
||||
return web.Response(status=404)
|
||||
owner_id = self.user_manager.get_request_user_id(request)
|
||||
result = resolve_hash_to_path(filename, owner_id=owner_id)
|
||||
if result is None:
|
||||
|
||||
@@ -118,6 +118,12 @@ def test_seed_scan_rejected(disabled_comfy):
|
||||
assert r.status_code == 503
|
||||
|
||||
|
||||
def test_view_blake3_hash_returns_404(disabled_comfy):
|
||||
base_url, _ = disabled_comfy
|
||||
r = requests.get(base_url + "/view", params={"filename": "blake3:" + "0" * 64}, timeout=30)
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_upload_image_skips_asset_registration(disabled_comfy):
|
||||
base_url, db_path = disabled_comfy
|
||||
files = {"image": ("disabled-mode-test.png", b"\x89PNG fake bytes", "image/png")}
|
||||
|
||||
Reference in New Issue
Block a user