From cb1183c7846b57e96aefd33721cb5b32bb271a97 Mon Sep 17 00:00:00 2001 From: Zlopez Date: Fri, 30 Jun 2023 14:54:37 +0200 Subject: [PATCH] Decode the topics in monitoring socket If the topics are encoded as bytes it will fail when trying to do json.dumps(). Let decode them if they are encoded. --- moksha.hub/moksha/hub/monitoring.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/moksha.hub/moksha/hub/monitoring.py b/moksha.hub/moksha/hub/monitoring.py index e7f45992..26fb12bc 100644 --- a/moksha.hub/moksha/hub/monitoring.py +++ b/moksha.hub/moksha/hub/monitoring.py @@ -71,6 +71,16 @@ def poll(self): "consumers": self.serialize(self.hub.consumers), "producers": self.serialize(self.hub.producers), } + # Decode topics if they are byte array + # This will prevent the json.dumps() to fail + for consumer in data["consumers"]: + decoded_topics = [] + for topic in consumer["topic"]: + if isinstance(topic, bytes): + decoded_topics.append(topic.decode()) + if decoded_topics: + consumer["topic"] = decoded_topics + if self.socket: self.socket.send_string(json.dumps(data))