From 8a532eb87129f86c17edb35ec914b4452c3cf808 Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Wed, 11 May 2011 15:21:03 +0200 Subject: [PATCH] [FIX] document: when updating attachment file size, exclude attachments having NULL db_datas (otherwise len() raises an exception) bzr revid: olt@tinyerp.com-20110511132103-3lu4657dmdhkdvex --- addons/document/document.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/document/document.py b/addons/document/document.py index 72012316d25..50769ea0fda 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -63,14 +63,14 @@ class document_file(osv.osv): cr.execute("UPDATE ir_attachment " \ "SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \ "WHERE parent_id IS NULL", (parent_id,)) - + cr.execute("ALTER TABLE ir_attachment ALTER parent_id SET NOT NULL") - + #Proceeding to update the filesize of the corresponsing attachment - cr.execute('SELECT id, db_datas FROM ir_attachment WHERE file_size=0') + cr.execute('SELECT id, db_datas FROM ir_attachment WHERE file_size=0 AND db_datas IS NOT NULL') old_attachments = cr.dictfetchall() - for attachment in old_attachments: + for attachment in old_attachments: f_size = len(attachment['db_datas']) cr.execute('UPDATE ir_attachment SET file_size=%s WHERE id=%s',(f_size,attachment['id']))