From eb9f05b0ac19ec208d309730539e9554807b232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pazos?= Date: Mon, 30 Mar 2026 14:58:59 -0300 Subject: [PATCH 1/2] Fix TypeError in _nonNegativeDelta when val is None and maxValue is set Move the None check before the maxValue/minValue comparisons to avoid comparing None against a float/int. --- webapp/graphite/render/functions.py | 8 ++++---- webapp/tests/test_functions.py | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/webapp/graphite/render/functions.py b/webapp/graphite/render/functions.py index 8630feb8f..b0e2dab91 100644 --- a/webapp/graphite/render/functions.py +++ b/webapp/graphite/render/functions.py @@ -2427,16 +2427,16 @@ def nonNegativeDerivative(requestContext, seriesList, maxValue=None, minValue=No def _nonNegativeDelta(val, prev, maxValue, minValue): + # first reading or None value + if None in (prev, val): + return None, val + # ignore values larger than maxValue if maxValue is not None and val > maxValue: return None, None if minValue is not None and val < minValue: return None, None - # first reading - if None in (prev, val): - return None, val - # counter increased, use the difference if val >= prev: return val - prev, val diff --git a/webapp/tests/test_functions.py b/webapp/tests/test_functions.py index cf3fce468..56f7dd959 100644 --- a/webapp/tests/test_functions.py +++ b/webapp/tests/test_functions.py @@ -1798,6 +1798,10 @@ def test_perSecond_nones(self): result = functions.scaleToSeconds({}, functions.nonNegativeDerivative({}, seriesList), 1) self.assertEqual(list(expected[0]), list(result[0])) + # None values should not raise TypeError when maxValue is set + result = functions.perSecond({}, seriesList, maxValue=1000) + self.assertEqual(list(expected[0]), list(result[0])) + def test_perSecond_max(self): seriesList = self._gen_series_list_with_data(key='test',start=0,end=600,step=60,data=[0, 120, 240, 480, 960, 900, 120, 240, 119, 479]) expected = [TimeSeries('perSecond(test)', 0, 600, 60, [None, 2, 2, 4, None, None, None, 2, 6, 6])] From f86f943e745ebd631a3ab320eda8602219c75f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pazos?= Date: Mon, 30 Mar 2026 17:22:41 -0300 Subject: [PATCH 2/2] preserve original behaviour --- webapp/graphite/render/functions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/graphite/render/functions.py b/webapp/graphite/render/functions.py index b0e2dab91..329149ff9 100644 --- a/webapp/graphite/render/functions.py +++ b/webapp/graphite/render/functions.py @@ -2427,9 +2427,8 @@ def nonNegativeDerivative(requestContext, seriesList, maxValue=None, minValue=No def _nonNegativeDelta(val, prev, maxValue, minValue): - # first reading or None value - if None in (prev, val): - return None, val + if val is None: + return None, None # ignore values larger than maxValue if maxValue is not None and val > maxValue: @@ -2437,6 +2436,10 @@ def _nonNegativeDelta(val, prev, maxValue, minValue): if minValue is not None and val < minValue: return None, None + # first reading + if prev is None: + return None, val + # counter increased, use the difference if val >= prev: return val - prev, val