From 5043b2924c9d12cb8b4377d6b1c70b682f4fe60f Mon Sep 17 00:00:00 2001 From: Afonso Coutinho Date: Thu, 4 Jun 2026 03:23:59 +0100 Subject: [PATCH] fix: image model ranking crashes when system is not a dict (#1900) --- services/hwfit/image_models.py | 2 ++ tests/test_image_models_nondict_system.py | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/test_image_models_nondict_system.py diff --git a/services/hwfit/image_models.py b/services/hwfit/image_models.py index eb418d6..088a00b 100644 --- a/services/hwfit/image_models.py +++ b/services/hwfit/image_models.py @@ -280,6 +280,8 @@ def rank_image_models(system, search=None, sort="fit"): Returns list of models with fit info (vram needed, fits, recommended quant). """ + if not isinstance(system, dict): + system = {} gpu_vram = system.get("gpu_vram_gb", 0) or 0 has_gpu = system.get("has_gpu", False) results = [] diff --git a/tests/test_image_models_nondict_system.py b/tests/test_image_models_nondict_system.py new file mode 100644 index 0000000..352d7f5 --- /dev/null +++ b/tests/test_image_models_nondict_system.py @@ -0,0 +1,9 @@ +from services.hwfit.image_models import rank_image_models, IMAGE_MODEL_REGISTRY + + +def test_rank_image_models_handles_non_dict_system(): + # `system` is the detected-hardware dict; if detection failed and returned + # None (or a non-dict), system.get(...) raised AttributeError. Treat a + # non-dict system as "unknown hardware" (no GPU) rather than crashing. + assert len(rank_image_models(None)) == len(IMAGE_MODEL_REGISTRY) + assert len(rank_image_models(123)) == len(IMAGE_MODEL_REGISTRY)