Compare the derived tag vocabulary as the database stores tag names

Stored tag names reach the database through normalize_tags, which strips
surrounding whitespace, but the vocabulary was built straight from registered
category names. A category registered as "vae " produced the entry
"model_type:vae " while the stored tag is "model_type:vae", so the entry never
matched and the stale automatic tag it exists to authorise removing survived
the reprojection.
This commit is contained in:
Simon Pinfold
2026-08-18 12:20:01 -07:00
parent f6ae4c948b
commit 52125ed00e
2 changed files with 31 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from pathlib import Path
from typing import Literal
import folder_paths
from app.assets.helpers import normalize_tags
_NON_MODEL_FOLDER_NAMES = frozenset({"configs", "custom_nodes"})
@@ -331,7 +332,10 @@ def get_path_derived_tag_vocabulary() -> set[str]:
vocabulary.update(_KNOWN_SUBFOLDER_TAGS)
for folder_name, _bases, _extensions in get_comfy_models_folders():
vocabulary.add(f"model_type:{folder_name}")
return vocabulary
# Stored tag names reach the database through normalize_tags, so an
# un-normalized vocabulary entry would never match one and the stale tag
# it is meant to authorise removing would survive.
return set(normalize_tags(list(vocabulary)))
def get_name_and_tags_from_asset_path(file_path: str) -> tuple[str, list[str]]:

View File

@@ -381,6 +381,32 @@ class TestTagReprojection:
)
assert "model_type:checkpoints" in _tags(session, "ref-1")
def test_vocabulary_matches_tags_as_the_database_stores_them(
self, session, comfy_dirs
):
"""Stored names arrive normalized, so a raw vocabulary entry never matches."""
path = _write(comfy_dirs["checkpoints"], "model.safetensors")
_register(
session,
path,
"ref-1",
tags={"model_type:loras": "automatic"},
)
with patch(
"app.assets.services.path_utils.get_comfy_models_folders",
return_value=[
("checkpoints", [str(comfy_dirs["checkpoints"])], {".safetensors"}),
("loras ", [str(comfy_dirs["loras"])], {".safetensors"}),
],
):
reproject_derived_state()
assert "model_type:loras" not in _tags(session, "ref-1"), (
"a category name with stray whitespace must not smuggle an entry "
"past the vocabulary and leave the stale tag in place"
)
def test_automatic_tag_outside_the_vocabulary_is_left_alone(
self, session, comfy_dirs
):