[FIX] mail: mail queue is interrupted if a recipient is not ascii valid

This is related to revision
71f188082f

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
This commit is contained in:
Denis Ledoux
2018-11-14 17:18:34 +01:00
parent c2827f6b72
commit c41902a21c
2 changed files with 8 additions and 8 deletions
+7 -7
View File
@@ -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
+1 -1
View File
@@ -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))