From 4535ce0f43097aa48e44a65747d82064f2aadaf5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 8 Mar 2024 21:12:24 -0500 Subject: [PATCH] Add sanity check for label value (#1012) Signed-off-by: Pengfei Zhang --- prometheus_client/metrics.py | 2 ++ tests/test_core.py | 1 + 2 files changed, 3 insertions(+) diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index 91cd9ecf..af512115 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -705,6 +705,8 @@ def info(self, val: Dict[str, str]) -> None: if self._labelname_set.intersection(val.keys()): raise ValueError('Overlapping labels for Info metric, metric: {} child: {}'.format( self._labelnames, val)) + if any(i is None for i in val.values()): + raise ValueError('Label value cannot be None') with self._lock: self._value = dict(val) diff --git a/tests/test_core.py b/tests/test_core.py index 30f9e0ad..8a54a02d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -534,6 +534,7 @@ def test_info(self): def test_labels(self): self.assertRaises(ValueError, self.labels.labels('a').info, {'l': ''}) + self.assertRaises(ValueError, self.labels.labels('a').info, {'il': None}) self.labels.labels('a').info({'foo': 'bar'}) self.assertEqual(1, self.registry.get_sample_value('il_info', {'l': 'a', 'foo': 'bar'}))