[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
This commit is contained in:
Olivier Dony
2012-06-22 11:31:23 +02:00
parent 838b035f5a
commit 95e00367f5
+3 -2
View File
@@ -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 \