From 21bde90c2ffd2fa128c9f0457a43b5ae2e58eea3 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 15 Jan 2018 13:00:28 +0000 Subject: [PATCH] [FIX] mail_tracking_mailgun: Avoid errors without event When this method is called without an event (a.k.a. `event=None`), this method produces the following error: ``` Traceback (most recent call last): File "/opt/odoo/auto/addons/mail/models/mail_mail.py", line 278, in send res = IrMailServer.send_email(msg, mail_server_id=mail.mail_server_id.id) File "/opt/odoo/auto/addons/mail_tracking/models/ir_mail_server.py", line 88, in send_email tracking_email.smtp_error(self, smtp_server_used, e) File "/opt/odoo/auto/addons/mail_tracking/models/mail_tracking_email.py", line 213, in smtp_error self.sudo()._partners_email_bounced_set('error') File "/opt/odoo/auto/addons/mail_tracking/models/mail_tracking_email.py", line 203, in _partners_email_bounced_set ]).email_bounced_set(self, reason, event=event) File "/opt/odoo/auto/addons/mail_tracking_mailgun/models/res_partner.py", line 22, in email_bounced_set self._email_bounced_set(reason, event) File "/opt/odoo/auto/addons/mail_tracking_mailgun/models/res_partner.py", line 33, in _email_bounced_set event['Message-Id'] or '') TypeError: 'NoneType' object has no attribute '__getitem__' ``` So, we now assume we do not always have an event. --- mail_tracking_mailgun/models/res_partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mail_tracking_mailgun/models/res_partner.py b/mail_tracking_mailgun/models/res_partner.py index 651b5cd7..9644e918 100644 --- a/mail_tracking_mailgun/models/res_partner.py +++ b/mail_tracking_mailgun/models/res_partner.py @@ -30,7 +30,8 @@ class ResPartner(models.Model): body = _('Email has been bounced: %s\n' 'Reason: %s\n' 'Event: %s') % (partner.email, reason, - event.get('Message-Id', _('unknown'))) + event and event.get('Message-Id', + _('unknown'))) partner.message_post(body=body) @api.multi