From 117b636d3fdcc32b1e430d41d245a7d8237ca87f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 25 Sep 2015 14:43:00 +0200 Subject: [PATCH] [FIX] mail: catch database errors when sending mails --- addons/mail/mail_mail.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 19852e1b182..aa02654ef58 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -26,6 +26,8 @@ from email.utils import formataddr from urllib import urlencode from urlparse import urljoin +import psycopg2 + from openerp import tools from openerp import SUPERUSER_ID from openerp.osv import fields, osv @@ -338,6 +340,12 @@ class mail_mail(osv.Model): # prevent catching transient MemoryErrors, bubble up to notify user or abort cron job # instead of marking the mail as failed raise + except psycopg2.Error: + # If an error with the database occurs, chances are that the cursor is unusable. + # This will lead to an `psycopg2.InternalError` being raised when trying to write + # `state`, shadowing the original exception and forbid a retry on concurrent + # update. Let's bubble it. + raise except Exception: _logger.exception('failed sending mail.mail %s', mail.id) mail.write({'state': 'exception'})