diff --git a/app/assets/services/path_utils.py b/app/assets/services/path_utils.py index d47fccd02..7bdec3d25 100644 --- a/app/assets/services/path_utils.py +++ b/app/assets/services/path_utils.py @@ -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]]: diff --git a/tests-unit/assets_test/test_semantics_reset.py b/tests-unit/assets_test/test_semantics_reset.py index 51453285a..0fcad4b70 100644 --- a/tests-unit/assets_test/test_semantics_reset.py +++ b/tests-unit/assets_test/test_semantics_reset.py @@ -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 ):