From ede97f3f3e61e8894c567fec5b9554c44c6948a3 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Wed, 25 Feb 2026 00:11:38 +0800 Subject: [PATCH] Fix calculate_recipe_fingerprint to handle non-string hash and invalid strength values - Handle non-string hash values by converting to string before lower() - Add try-except for strength conversion to handle invalid values like empty strings - Fixes hypothesis test failures when random data generates unexpected types --- py/utils/utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/py/utils/utils.py b/py/utils/utils.py index 200ec47a..af9bfe86 100644 --- a/py/utils/utils.py +++ b/py/utils/utils.py @@ -189,15 +189,23 @@ def calculate_recipe_fingerprint(loras): if lora.get("exclude", False): continue - hash_value = lora.get("hash", "").lower() + hash_value = lora.get("hash", "") + if isinstance(hash_value, str): + hash_value = hash_value.lower() + else: + hash_value = str(hash_value).lower() if hash_value else "" if not hash_value and lora.get("modelVersionId"): hash_value = str(lora.get("modelVersionId")) - + if not hash_value: continue - + # Normalize strength to 2 decimal places (check both strength and weight fields) - strength = round(float(lora.get("strength", lora.get("weight", 1.0))), 2) + strength_val = lora.get("strength", lora.get("weight", 1.0)) + try: + strength = round(float(strength_val), 2) + except (ValueError, TypeError): + strength = 1.0 valid_loras.append((hash_value, strength))