From 95e00367f59083afa22f987a77fead3e81a1de29 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 22 Jun 2012 11:31:23 +0200 Subject: [PATCH] [FIX] mail: avoid obscure failure when processing batches of emails with attachments This issue was caused by the way browse_records are cached, in combination with the deletion of messages just after sending them. When processing a second message, the attachment.datas function fields gets computed for all messages that are being browsed, including the first message that was already deleted, causing an exception. The value of the function field had already been computed for the first message, but had been discarded by the message.refresh() call. Hopefully this kind of issue will disappear once we implement the new ORM API. bzr revid: odo@openerp.com-20120622093123-wpk8ht454w7p2c1w --- addons/mail/mail_message.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 24c91fa6f3c..5c2229d49bc 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -518,12 +518,13 @@ class mail_message(osv.osv): context=context) if res: message.write({'state':'sent', 'message_id': res}) + message_sent = True else: message.write({'state':'exception'}) + message_sent = False # if auto_delete=True then delete that sent messages as well as attachments - message.refresh() - if message.state == 'sent' and message.auto_delete: + if message_sent and message.auto_delete: self.pool.get('ir.attachment').unlink(cr, uid, [x.id for x in message.attachment_ids \ if x.res_model == self._name and \