Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
push_notifications: Drop error messages from failure to send.
Alex Vandiver69825cd54c08
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex 49f2269bad1..eeb93e7da35 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -135,10 +135,6 @@ def get_apns_context() -> Optional[APNsContext]:# import time.import aioapns- # aioapns logs at "error" level for every non-successful request,- # which fills the logs; see https://github.com/Fatal1ty/aioapns/issues/15- logging.getLogger("aioapns").setLevel(logging.CRITICAL)-if settings.APNS_CERT_FILE is None: # nocoveragereturn None@@ -147,12 +143,22 @@ def get_apns_context() -> Optional[APNsContext]:# hammered with a ton of these all at once after startup.loop = asyncio.new_event_loop()+ # Defining a no-op error-handling function overrides the default+ # behaviour of logging at ERROR level whenever delivery fails; we+ # handle those errors by checking the result in+ # send_apple_push_notification.+ async def err_func(+ request: aioapns.NotificationRequest, result: aioapns.common.NotificationResult+ ) -> None:+ pass # nocoverage+async def make_apns() -> aioapns.APNs:return aioapns.APNs(client_cert=settings.APNS_CERT_FILE,topic=settings.APNS_TOPIC,max_connection_attempts=APNS_MAX_RETRIES,use_sandbox=settings.APNS_SANDBOX,+ err_func=err_func,)apns = loop.run_until_complete(make_apns())diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.pyindex 329315118b8..aa8f3af0730 100644--- a/zerver/tests/test_push_notifications.py+++ b/zerver/tests/test_push_notifications.py@@ -999,7 +999,10 @@ class PushNotificationTest(BouncerTestCase):def mock_apns(self) -> Iterator[Tuple[APNsContext, mock.AsyncMock]]:apns = mock.Mock(spec=aioapns.APNs)apns.send_notification = mock.AsyncMock()- apns_context = APNsContext(apns=apns, loop=asyncio.new_event_loop())+ apns_context = APNsContext(+ apns=apns,+ loop=asyncio.new_event_loop(),+ )try:with mock.patch("zerver.lib.push_notifications.get_apns_context") as mock_get:mock_get.return_value = apns_context