mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Mailgun: fix webhook error with null delivery-status
Mailgun now sometimes posts `"delivery-status": null` in the tracking event payload. Avoid raising an AttributeError when that occurs. Fixes #361
This commit is contained in:
@@ -44,6 +44,13 @@ Features
|
||||
(Thanks to `@Arondit`_ for the implementation.)
|
||||
|
||||
|
||||
Fixes
|
||||
~~~~~
|
||||
|
||||
* **Mailgun:** Avoid an error when Mailgun posts null delivery-status
|
||||
to the event tracking webhook. (Thanks to `@izimobil`_ for the fix.)
|
||||
|
||||
|
||||
v10.2
|
||||
-----
|
||||
|
||||
@@ -1595,6 +1602,7 @@ Features
|
||||
.. _@Flexonze: https://github.com/Flexonze
|
||||
.. _@gdvalderrama: https://github.com/gdvalderrama
|
||||
.. _@Honza-m: https://github.com/Honza-m
|
||||
.. _@izimobil: https://github.com/izimobil
|
||||
.. _@janneThoft: https://github.com/janneThoft
|
||||
.. _@jc-ee: https://github.com/jc-ee
|
||||
.. _@joshkersey: https://github.com/joshkersey
|
||||
|
||||
@@ -172,12 +172,12 @@ class MailgunTrackingWebhookView(MailgunBaseWebhookView):
|
||||
|
||||
try:
|
||||
delivery_status = event_data["delivery-status"]
|
||||
except KeyError:
|
||||
description = None
|
||||
mta_response = None
|
||||
else:
|
||||
# if delivery_status is None, an AttributeError will be raised
|
||||
description = delivery_status.get("description")
|
||||
mta_response = delivery_status.get("message")
|
||||
except (KeyError, AttributeError):
|
||||
description = None
|
||||
mta_response = None
|
||||
|
||||
if "reason" in event_data:
|
||||
reject_reason = self.reject_reasons.get(
|
||||
|
||||
@@ -630,6 +630,22 @@ class MailgunTestCase(WebhookTestCase):
|
||||
self.assertEqual(event.event_type, "clicked")
|
||||
self.assertEqual(event.click_url, "https://example.com/test")
|
||||
|
||||
def test_delivery_status_is_none_event(self):
|
||||
raw_event = mailgun_sign_payload(
|
||||
{
|
||||
"event-data": {
|
||||
"event": "accepted",
|
||||
"delivery-status": None,
|
||||
}
|
||||
}
|
||||
)
|
||||
response = self.client.post(
|
||||
"/anymail/mailgun/tracking/",
|
||||
data=json.dumps(raw_event),
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@tag("mailgun")
|
||||
@override_settings(ANYMAIL_MAILGUN_WEBHOOK_SIGNING_KEY=TEST_WEBHOOK_SIGNING_KEY)
|
||||
|
||||
Reference in New Issue
Block a user