From 7224d871356693d69faa3c3adbc918fd7987530f Mon Sep 17 00:00:00 2001 From: Dariusz L Date: Sun, 7 Jun 2026 14:40:44 +0200 Subject: [PATCH] fix: replace substring alias matching with exact membership check in _base_model_matches Uses an exact alias membership check instead of substring matching to prevent false positives, e.g. 'zimage' alias no longer incorrectly matches 'zimagebase'. --- core/sources/civarchive.py | 11 +++++++---- core/sources/civitai.py | 11 +++++++---- core/sources/lora_manager_archive.py | 11 +++++++---- metadata/base-models.meta.json | 6 +++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/sources/civarchive.py b/core/sources/civarchive.py index 11c6029..14e6137 100644 --- a/core/sources/civarchive.py +++ b/core/sources/civarchive.py @@ -501,11 +501,14 @@ def _base_model_matches(candidate: str, preferred: Optional[str]) -> bool: from .popular import load_base_model_aliases aliases = load_base_model_aliases() + # Exact alias membership check - avoids false positives from substring matching + # e.g. prevents "zimage" (Z-Image alias) from matching "zimagebase" (ZImageBase) preferred_tokens = aliases.get(preferred_norm, [preferred_norm]) - return any( - token and (token in candidate_norm or candidate_norm in token) - for token in preferred_tokens - ) + if candidate_norm in preferred_tokens: + return True + # Symmetric check: if preferred is an alias of candidate's model family + candidate_tokens = aliases.get(candidate_norm, [candidate_norm]) + return preferred_norm in candidate_tokens def _base_model_score(candidate: str, preferred: Optional[str]) -> float: diff --git a/core/sources/civitai.py b/core/sources/civitai.py index 79be7b8..f0824f2 100644 --- a/core/sources/civitai.py +++ b/core/sources/civitai.py @@ -276,11 +276,14 @@ def _base_model_matches(candidate: str, preferred: Optional[str]) -> bool: from .popular import load_base_model_aliases aliases = load_base_model_aliases() + # Exact alias membership check - avoids false positives from substring matching + # e.g. prevents "zimage" (Z-Image alias) from matching "zimagebase" (ZImageBase) preferred_tokens = aliases.get(preferred_norm, [preferred_norm]) - return any( - token and (token in candidate_norm or candidate_norm in token) - for token in preferred_tokens - ) + if candidate_norm in preferred_tokens: + return True + # Symmetric check: if preferred is an alias of candidate's model family + candidate_tokens = aliases.get(candidate_norm, [candidate_norm]) + return preferred_norm in candidate_tokens def _base_model_score(candidate: str, preferred: Optional[str]) -> float: diff --git a/core/sources/lora_manager_archive.py b/core/sources/lora_manager_archive.py index 968c738..2990e19 100644 --- a/core/sources/lora_manager_archive.py +++ b/core/sources/lora_manager_archive.py @@ -168,11 +168,14 @@ def _base_model_matches(candidate: str, preferred: Optional[str]) -> bool: from .popular import load_base_model_aliases aliases = load_base_model_aliases() + # Exact alias membership check - avoids false positives from substring matching + # e.g. prevents "zimage" (Z-Image alias) from matching "zimagebase" (ZImageBase) preferred_tokens = aliases.get(preferred_norm, [preferred_norm]) - return any( - token and (token in candidate_norm or candidate_norm in token) - for token in preferred_tokens - ) + if candidate_norm in preferred_tokens: + return True + # Symmetric check: if preferred is an alias of candidate's model family + candidate_tokens = aliases.get(candidate_norm, [candidate_norm]) + return preferred_norm in candidate_tokens def _base_model_score(candidate: str, preferred: Optional[str]) -> float: diff --git a/metadata/base-models.meta.json b/metadata/base-models.meta.json index c3b7b86..fdb2e42 100644 --- a/metadata/base-models.meta.json +++ b/metadata/base-models.meta.json @@ -1,6 +1,6 @@ { - "updated_at": "2026-06-06T17:28:12+00:00", - "last_checked_at": "2026-06-06T17:28:12+00:00", + "updated_at": "2026-06-06T17:43:51+00:00", + "last_checked_at": "2026-06-06T17:43:51+00:00", "local_count": 91, - "new_models_added": 79 + "new_models_added": 0 }