From eefb88f0eaa8089b0959e6340e349d8c23557a1d Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 31 Oct 2025 23:47:27 +0530 Subject: [PATCH] push_notification: Fix invalid `data` arg to firebase_messaging.Message. Earlier, we were passing invalid `data` argument to `firebase_messaging.Message` which would result in an error while sending E2EE push notification for android devices. The API requires all keys and values in the `data` dictionary to be strings. One of the value was an integer. This commit fixes the bug by converting the values to str if they are not. Signed-off-by: Prakhar Pratyush --- zerver/lib/push_notifications.py | 3 +++ zilencer/lib/push_notifications.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index 6769b76568..ca05ce5e68 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -1447,6 +1447,9 @@ APNsPriority: TypeAlias = Literal[10, 5, 1] @dataclass class PushRequestBasePayload: + # FCM expects in this type must always be strings. Non-string + # fields must be converted into strings in the FCM code path + # within send_e2ee_push_notifications. push_account_id: int encrypted_data: str diff --git a/zilencer/lib/push_notifications.py b/zilencer/lib/push_notifications.py index f1f5466600..891225c4ce 100644 --- a/zilencer/lib/push_notifications.py +++ b/zilencer/lib/push_notifications.py @@ -196,9 +196,14 @@ def send_e2ee_push_notifications( apns_remote_push_devices.append(remote_push_device) else: assert isinstance(push_request, FCMPushRequest) + fcm_payload = dict( + # FCM only allows string values, so we stringify push_account_id. + push_account_id=str(push_request.payload.push_account_id), + encrypted_data=push_request.payload.encrypted_data, + ) fcm_requests.append( firebase_messaging.Message( - data=asdict(push_request.payload), + data=fcm_payload, token=remote_push_device.token, android=firebase_messaging.AndroidConfig(priority=push_request.fcm_priority), )