From 3416347a1f79a0e0b065eeda42fb35fb50893ede Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Sat, 1 Feb 2025 22:28:17 -0500 Subject: [PATCH] server/python: fix hash calculation (#1720) --- server/python/cluster_setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/python/cluster_setup.py b/server/python/cluster_setup.py index 6b858b610..66323e192 100644 --- a/server/python/cluster_setup.py +++ b/server/python/cluster_setup.py @@ -144,7 +144,11 @@ class ClusterSetup: m = hashlib.sha256() m.update( bytes( - f"{o['id']}{o.get('address', '')}{o['port']}{o.get('sourceKey', '')}{o['proxyId']}{self.clusterSecret}", + # The use of ` o.get(key, None) or '' ` is to ensure that optional fields + # are omitted from the hash, matching the JS implementation. Otherwise, since + # the dict may contain the keys initialized to None, ` o.get(key, '') ` would + # return None instead of ''. + f"{o['id']}{o.get('address', None) or ''}{o['port']}{o.get('sourceKey', None) or ''}{o['proxyId']}{self.clusterSecret}", "utf8", ) )