diff options
| author | P. Christeas <p_christ@hol.gr> | 2010-07-01 20:51:32 +0300 |
|---|---|---|
| committer | P. Christeas <p_christ@hol.gr> | 2010-07-01 20:51:32 +0300 |
| commit | 4913a2f0dba67d082e225bafa97b4c576e4f8cb7 (patch) | |
| tree | 989c6ae75ebdd959d5b9bc9e3815e7e1aea9d193 /addons/document/document_storage.py | |
| parent | abebb5c31194e86af9bf6326f4f6a4980f17be1c (diff) | |
Document: fix nodefd_db.close()
Some vars were missing/inaccessible, put the queries in a try block.
bzr revid: p_christ@hol.gr-20100701175132-389l8frlqqg7hgr3
Diffstat (limited to 'addons/document/document_storage.py')
| -rw-r--r-- | addons/document/document_storage.py | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/addons/document/document_storage.py b/addons/document/document_storage.py index 26ba5dea772..08d3d82893b 100644 --- a/addons/document/document_storage.py +++ b/addons/document/document_storage.py @@ -35,6 +35,7 @@ from osv.orm import except_orm import random import string +import pooler import netsvc import nodes from content_index import cntIndex @@ -129,21 +130,27 @@ class nodefd_db(StringIO, nodes.node_descriptor): def close(self): # we now open a *separate* cursor, to update the data. # FIXME: this may be improved, for concurrency handling - uid = self.__parent.context.uid - cr = pooler.get_db(self.__parent.context.dbname).cursor() - if mode == 'w': - out = self.getvalue() - cr.execute('UPDATE ir_attachment SET db_datas = %s, file_size=%d WHERE id = %s', - (out, len(out), self.__parent.file_id)) - elif mode == 'a': - out = self.getvalue() - cr.execute("UPDATE ir_attachment " \ - "SET db_datas = COALESCE(db_datas,'') || %s, " \ - " file_size = COALESCE(file_size, 0) + %d " \ - " WHERE id = %s", - (out, len(out), self.__parent.file_id)) - cr.commit() - cr.close() + par = self._get_parent() + uid = par.context.uid + cr = pooler.get_db(par.context.dbname).cursor() + try: + if self.mode == 'w': + out = self.getvalue() + cr.execute('UPDATE ir_attachment SET db_datas = %s, file_size=%d WHERE id = %s', + (out, len(out), par.file_id)) + elif self.mode == 'a': + out = self.getvalue() + cr.execute("UPDATE ir_attachment " \ + "SET db_datas = COALESCE(db_datas,'') || %s, " \ + " file_size = COALESCE(file_size, 0) + %d " \ + " WHERE id = %s", + (out, len(out), par.file_id)) + cr.commit() + except Exception, e: + logging.getLogger('document.storage').exception('Cannot update db file #%d for close:', par.file_id) + raise + finally: + cr.close() StringIO.close(self) class document_storage(osv.osv): |
