From 92b23970f032cbc990aa0e501708c425708e51ea Mon Sep 17 00:00:00 2001 From: GlorifiedPig Date: Fri, 6 Dec 2024 17:25:05 +0200 Subject: [PATCH] if check before deleting in remove() (#1077) Signed-off-by: GlorifiedPig --- prometheus_client/metrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index 9b251274..b9f25ffc 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -200,7 +200,8 @@ def remove(self, *labelvalues: Any) -> None: raise ValueError('Incorrect label count (expected %d, got %s)' % (len(self._labelnames), labelvalues)) labelvalues = tuple(str(l) for l in labelvalues) with self._lock: - del self._metrics[labelvalues] + if labelvalues in self._metrics: + del self._metrics[labelvalues] def clear(self) -> None: """Remove all labelsets from the metric"""