Просмотр исходного кода

util: look up the integer range by string key, not the range builtin (#5384)

representation() called dp._config.get(range) when building a sample
DPS value for an integer datapoint. The dict comes from YAML, so all
keys are strings; passing the built-in range() function as a key meant
the lookup always returned None and the configured min was ignored,
falling back to 0 for every int DP. Read the 'range' string key instead,
and guard against a non-dict or missing 'min' before subscripting.

This matters for the CLI utilities (duplicates, match_against) that
consume make_sample_dps: a device with range.min: 40 was producing a
sample of 0, which can fail _typematch against configs that require
values in [40, 70] and turn a real-match case into a false negative.

Co-authored-by: Zo Bot <github-automation@zo.computer>
Hrachya Shaginyan 1 неделя назад
Родитель
Сommit
acaabe3552
1 измененных файлов с 3 добавлено и 2 удалено
  1. 3 2
      util/common_funcs.py

+ 3 - 2
util/common_funcs.py

@@ -32,8 +32,9 @@ def representation(dp):
     if dp.type is bool:
         return True
     if dp.type is int:
-        if dp._config.get(range):
-            return dp._config.get(range)["min"]
+        range_spec = dp._config.get("range")
+        if isinstance(range_spec, dict) and "min" in range_spec:
+            return range_spec["min"]
         return 0
     if dp.type is str:
         return ""