From 6e2eeeedcc9611b3fff7e9597ba620707f0c3d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Thu, 2 Oct 2025 09:30:36 -0400 Subject: [PATCH] Allow creation of Metric from datastructure without __name__ When applying a function to a time series in a query to Prometheus, the Prometheus server returns a data structure without __name__ key. Apart from that aspect, the time series could still be used to create a Metric object. This PR proposes to set "metric_name" to None when __name__ is missing. --- prometheus_api_client/metric.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prometheus_api_client/metric.py b/prometheus_api_client/metric.py index 3ff971e..0ecb899 100644 --- a/prometheus_api_client/metric.py +++ b/prometheus_api_client/metric.py @@ -54,10 +54,9 @@ def __init__(self, metric, oldest_data_datetime=None): self.metric_values = metric.metric_values self.oldest_data_datetime = oldest_data_datetime else: - self.metric_name = metric["metric"]["__name__"] + self.metric_name = metric["metric"].pop("__name__", None) self.label_config = deepcopy(metric["metric"]) self.oldest_data_datetime = oldest_data_datetime - del self.label_config["__name__"] # if it is a single value metric change key name if "value" in metric: