diff options
| author | Christophe Simonis <chs@openerp.com> | 2014-05-07 18:00:23 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@openerp.com> | 2014-05-07 18:00:23 +0200 |
| commit | 1091b24a0c659e6e7ad3ca0d6ba7141617ddcb4c (patch) | |
| tree | 142b61f0833a0224dec04d3ee5f6c03c44304001 /addons/mail/mail_mail.py | |
| parent | 643871c20f096223b38ef69e846dcaa9f1e44051 (diff) | |
| parent | 1953aa442fb2f6cc4d0e64bbfcc1f9a461f14a02 (diff) | |
[MERGE] forward port of branch saas-3 up to revid 9450 chs@openerp.com-20140507153348-g2qw61dkxvps13br
bzr revid: chs@openerp.com-20140507160023-8wwqlbf3bv7yqe67
Diffstat (limited to 'addons/mail/mail_mail.py')
| -rw-r--r-- | addons/mail/mail_mail.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index a32d82e221e..c4466a9f0c4 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -234,13 +234,17 @@ class mail_mail(osv.Model): :return: True """ ir_mail_server = self.pool.get('ir.mail_server') + ir_attachment = self.pool['ir.attachment'] for mail in self.browse(cr, SUPERUSER_ID, ids, context=context): try: - # handle attachments - attachments = [] - for attach in mail.attachment_ids: - attachments.append((attach.datas_fname, base64.b64decode(attach.datas))) + # load attachment binary data with a separate read(), as prefetching all + # `datas` (binary field) could bloat the browse cache, triggerring + # soft/hard mem limits with temporary data. + attachment_ids = [a.id for a in mail.attachment_ids] + attachments = [(a['datas_fname'], base64.b64decode(a['datas'])) + for a in ir_attachment.read(cr, SUPERUSER_ID, attachment_ids, + ['datas_fname', 'datas'])] # specific behavior to customize the send email for notified partners email_list = [] if mail.email_to: @@ -289,6 +293,14 @@ class mail_mail(osv.Model): # /!\ can't use mail.state here, as mail.refresh() will cause an error # see revid:odo@openerp.com-20120622152536-42b2s28lvdv3odyr in 6.1 self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=mail_sent) + _logger.info('Mail with ID %r and Message-Id %r successfully sent', mail.id, mail.message_id) + except MemoryError: + # prevent catching transient MemoryErrors, bubble up to notify user or abort cron job + # instead of marking the mail as failed + _logger.exception('MemoryError while processing mail with ID %r and Msg-Id %r. '\ + 'Consider raising the --limit-memory-hard startup option', + mail.id, mail.message_id) + raise except Exception as e: _logger.exception('failed sending mail.mail %s', mail.id) mail.write({'state': 'exception'}) |
