From d0fe28cfe2299e16d0eddae042ddd0ef0ab8feb9 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 28 Sep 2025 09:18:59 +0800 Subject: [PATCH] fix(recipe): validate modelVersionId before fetching hash from cache or Civitai --- py/services/recipe_scanner.py | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/py/services/recipe_scanner.py b/py/services/recipe_scanner.py index 9a82b237..58894364 100644 --- a/py/services/recipe_scanner.py +++ b/py/services/recipe_scanner.py @@ -424,27 +424,29 @@ class RecipeScanner: # If has modelVersionId but no hash, look in lora cache first, then fetch from Civitai if 'modelVersionId' in lora and not lora.get('hash'): model_version_id = lora['modelVersionId'] + # Check if model_version_id is an integer and > 0 + if isinstance(model_version_id, int) and model_version_id > 0: - # Try to find in lora cache first - hash_from_cache = await self._find_hash_in_lora_cache(model_version_id) - if hash_from_cache: - lora['hash'] = hash_from_cache - metadata_updated = True - else: - # If not in cache, fetch from Civitai - result = await self._get_hash_from_civitai(model_version_id) - if isinstance(result, tuple): - hash_from_civitai, is_deleted = result - if hash_from_civitai: - lora['hash'] = hash_from_civitai - metadata_updated = True - elif is_deleted: - # Mark the lora as deleted if it was not found on Civitai - lora['isDeleted'] = True - logger.warning(f"Marked lora with modelVersionId {model_version_id} as deleted") - metadata_updated = True + # Try to find in lora cache first + hash_from_cache = await self._find_hash_in_lora_cache(model_version_id) + if hash_from_cache: + lora['hash'] = hash_from_cache + metadata_updated = True else: - logger.debug(f"Could not get hash for modelVersionId {model_version_id}") + # If not in cache, fetch from Civitai + result = await self._get_hash_from_civitai(model_version_id) + if isinstance(result, tuple): + hash_from_civitai, is_deleted = result + if hash_from_civitai: + lora['hash'] = hash_from_civitai + metadata_updated = True + elif is_deleted: + # Mark the lora as deleted if it was not found on Civitai + lora['isDeleted'] = True + logger.warning(f"Marked lora with modelVersionId {model_version_id} as deleted") + metadata_updated = True + else: + logger.debug(f"Could not get hash for modelVersionId {model_version_id}") # If has hash but no file_name, look up in lora library if 'hash' in lora and (not lora.get('file_name') or not lora['file_name']):