From 04f8aa18335e5ed76e4e099027a6841f986eb091 Mon Sep 17 00:00:00 2001 From: Afonso Coutinho Date: Wed, 3 Jun 2026 06:11:10 +0100 Subject: [PATCH] fix: _lookup_bandwidth crashes on a truthy non-string gpu_name (#1641) --- services/hwfit/fit.py | 2 +- tests/test_hwfit_bandwidth_nonstring.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/test_hwfit_bandwidth_nonstring.py diff --git a/services/hwfit/fit.py b/services/hwfit/fit.py index 9e80ced..fb0e006 100644 --- a/services/hwfit/fit.py +++ b/services/hwfit/fit.py @@ -61,7 +61,7 @@ CONTEXT_TARGET = { def _lookup_bandwidth(gpu_name): - if not gpu_name: + if not isinstance(gpu_name, str) or not gpu_name: return None gn = gpu_name.lower() for key in _BW_KEYS_SORTED: diff --git a/tests/test_hwfit_bandwidth_nonstring.py b/tests/test_hwfit_bandwidth_nonstring.py new file mode 100644 index 0000000..4b5e496 --- /dev/null +++ b/tests/test_hwfit_bandwidth_nonstring.py @@ -0,0 +1,16 @@ +"""Regression: _lookup_bandwidth must tolerate a non-string gpu_name. + +It guarded only falsy values; a truthy non-string (e.g. a number from a +malformed hardware probe) reached `gpu_name.lower()` and raised AttributeError. +""" +from services.hwfit.fit import _lookup_bandwidth + + +def test_non_string_returns_none(): + assert _lookup_bandwidth(123) is None + assert _lookup_bandwidth(["x"]) is None + assert _lookup_bandwidth(None) is None + + +def test_known_gpu_resolves(): + assert _lookup_bandwidth("NVIDIA GeForce RTX 4090") is not None