From c41902a21c50e0accc1b9d6bfa60bce8ecbb5955 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 14 Nov 2018 17:15:08 +0100 Subject: [PATCH] [FIX] mail: mail queue is interrupted if a recipient is not ascii valid This is related to revision 71f188082fff062a708a68e799ca1f3000fa21fb This is nice to have a meaningful explanation for the user to understand why his mail is not sent, this is better to not interrupt the mail queue when doing so. Because of the above revision, when the mail queue iterated on a mail failing because of an ASCII encoding issue, the mail queue was interrupted, and on the next cron call it failed again and again on the same mail, therefore leading to the mail queue to never be processed. Fixes #27804 --- addons/mail/models/mail_mail.py | 14 +++++++------- addons/test_mail/tests/test_mail_mail.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index aea14012767..6a50a198347 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -375,9 +375,6 @@ class MailMail(models.Model): # /!\ can't use mail.state here, as mail.refresh() will cause an error # see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1 mail._postprocess_sent_message(success_pids=success_pids, failure_type=failure_type) - except UnicodeEncodeError as exc: - _logger.exception('UnicodeEncodeError on text "%s" while processing mail ID %r.', exc.object, mail.id) - raise MailDeliveryException(_("Mail Delivery Failed"), "Invalid text: %s" % exc.object) except MemoryError: # prevent catching transient MemoryErrors, bubble up to notify user or abort cron job # instead of marking the mail as failed @@ -398,10 +395,13 @@ class MailMail(models.Model): mail.write({'state': 'exception', 'failure_reason': failure_reason}) mail._postprocess_sent_message(success_pids=success_pids, failure_reason=failure_reason, failure_type='UNKNOWN') if raise_exception: - if isinstance(e, AssertionError): - # get the args of the original error, wrap into a value and throw a MailDeliveryException - # that is an except_orm, with name and value as arguments - value = '. '.join(e.args) + if isinstance(e, (AssertionError, UnicodeEncodeError)): + if isinstance(e, UnicodeEncodeError): + value = "Invalid text: %s" % e.object + else: + # get the args of the original error, wrap into a value and throw a MailDeliveryException + # that is an except_orm, with name and value as arguments + value = '. '.join(e.args) raise MailDeliveryException(_("Mail Delivery Failed"), value) raise diff --git a/addons/test_mail/tests/test_mail_mail.py b/addons/test_mail/tests/test_mail_mail.py index 207cc80d26f..aebb4734fc3 100644 --- a/addons/test_mail/tests/test_mail_mail.py +++ b/addons/test_mail/tests/test_mail_mail.py @@ -48,4 +48,4 @@ class TestMail(common.SavepointCase, mail_common.MockEmails): 'partner_ids': [(4, self.user_employee.partner_id.id)] }) - self.assertRaises(MailDeliveryException, mail.send) + self.assertRaises(MailDeliveryException, lambda: mail.send(raise_exception=True))