diff --git a/core/metadata_model_utils.py b/core/metadata_model_utils.py index 0758726..eb7bd1c 100644 --- a/core/metadata_model_utils.py +++ b/core/metadata_model_utils.py @@ -24,13 +24,7 @@ def model_identity_key(model: Dict[str, Any]) -> str: model_path = str(model.get("path") or "").strip() if not model_path: return "" - try: - return get_path_identity(model_path) - except (OSError, ValueError): - try: - return os.path.normcase(os.path.abspath(model_path)) - except (OSError, ValueError): - return os.path.normcase(model_path) + return get_path_identity(model_path) def dedupe_models(models: List[Dict[str, Any]]) -> List[Dict[str, Any]]: diff --git a/core/scanner.py b/core/scanner.py index 47f9cf3..75bb2ab 100644 --- a/core/scanner.py +++ b/core/scanner.py @@ -41,11 +41,7 @@ def _model_identity(model: Dict[str, str]) -> str: path = model.get("path", "") if not path: return "" - - try: - return _path_identity(path) - except (OSError, ValueError): - return os.path.normcase(os.path.abspath(path)) + return _path_identity(path) def get_model_directories() -> Dict[str, Tuple[List[str], set]]: diff --git a/tests/test_metadata_model_helpers.py b/tests/test_metadata_model_helpers.py index 9589167..0c218ce 100644 --- a/tests/test_metadata_model_helpers.py +++ b/tests/test_metadata_model_helpers.py @@ -1,8 +1,10 @@ import os import tempfile import unittest +from unittest.mock import patch from core.metadata_model_utils import dedupe_models, is_model_file_path, model_identity_key +from core.scanner import _model_identity class MetadataModelHelperTests(unittest.TestCase): @@ -45,6 +47,14 @@ class MetadataModelHelperTests(unittest.TestCase): self.assertEqual("", model_identity_key(empty)) self.assertEqual([first], dedupe_models(models)) + def test_scanner_and_metadata_identity_share_path_fallback(self): + model_path = os.path.join("models", "model.safetensors") + expected = os.path.normcase(os.path.abspath(model_path)) + + with patch("core.path_utils.os.path.realpath", side_effect=OSError): + self.assertEqual(expected, _model_identity({"path": model_path})) + self.assertEqual(expected, model_identity_key({"path": model_path})) + if __name__ == "__main__": unittest.main()