From c59b143d962c4af378521176892bc614a1babeff Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Mon, 2 Aug 2021 23:41:55 +0800 Subject: [PATCH] api: Make `update_user_by_id` compatible. As part of supporting the change in zulip/zulip#18409, we add a conditional to send the old/buggy format only to servers with feature levels indicating they don't support the modern version. --- zulip/zulip/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 15b5de8..e1646d9 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -1308,8 +1308,11 @@ class Client: {'result': 'success', 'msg': ''} """ - for key, value in request.items(): - request[key] = json.dumps(value) + if "full_name" in request and self.feature_level < 106: + # As noted in https://github.com/zulip/zulip/issues/18409, + # before feature level 106, the server expected a + # buggy double JSON encoding of the `full_name` parameter. + request["full_name"] = json.dumps(request["full_name"]) return self.call_endpoint(url=f"users/{user_id}", method="PATCH", request=request)