[FIX] mail: catch database errors when sending mails

This commit is contained in:
Christophe Simonis 2015-09-25 14:43:00 +02:00
parent fc11b58239
commit 117b636d3f
1 changed files with 8 additions and 0 deletions

View File

@ -26,6 +26,8 @@ from email.utils import formataddr
from urllib import urlencode from urllib import urlencode
from urlparse import urljoin from urlparse import urljoin
import psycopg2
from openerp import tools from openerp import tools
from openerp import SUPERUSER_ID from openerp import SUPERUSER_ID
from openerp.osv import fields, osv 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 # prevent catching transient MemoryErrors, bubble up to notify user or abort cron job
# instead of marking the mail as failed # instead of marking the mail as failed
raise 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: except Exception:
_logger.exception('failed sending mail.mail %s', mail.id) _logger.exception('failed sending mail.mail %s', mail.id)
mail.write({'state': 'exception'}) mail.write({'state': 'exception'})