From 5d6656d739feff7abb8e191fdc038cc03b542d3b Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 15 May 2019 09:16:23 +0000 Subject: [PATCH] [FIX] mail: avoid concurrent update of notifications This revision is a backport of revision 56596e5240ef920df14d99087451ce6f06ac6d36 As the bug mentioned in the above revision occurs as well in Odoo 10.0 and 11.0. opw-1984293 closes odoo/odoo#33382 Signed-off-by: Denis Ledoux --- addons/mail/models/mail_mail.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 87305781784..27313fdb59d 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -267,6 +267,19 @@ class MailMail(models.Model): }) mail_sent = False + # Update notification in a transient exception state to avoid concurrent + # update in case an email bounces while sending all emails related to current + # mail record. + notifs = self.env['mail.notification'].search([ + ('is_email', '=', True), + ('mail_message_id', 'in', mail.mapped('mail_message_id').ids), + ('email_status', 'not in', ('sent', 'canceled')) + ]) + if notifs: + notifs.sudo().write({ + 'email_status': 'exception', + }) + # build an RFC2822 email.message.Message object and send it without queuing res = None for email in email_list: