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))