From 8307ff013916ffcaf8c7f0c8a796df77a64bfcd4 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:31 +0300 Subject: [PATCH] Document: workaround case when text file consists of non-unicode. The content indexer would be trying to process the garbage of the file and fail. bzr revid: p_christ@hol.gr-20100701175131-b83jg498xjuosmd9 --- addons/document/document_storage.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/document/document_storage.py b/addons/document/document_storage.py index b2db4eb36a6..26ba5dea772 100644 --- a/addons/document/document_storage.py +++ b/addons/document/document_storage.py @@ -378,16 +378,21 @@ class document_storage(osv.osv): self._doclog.debug('Cannot index file:', exc_info=True) pass + try: + icont_u = ustr(icont) + except UnicodeError: + icont_u = '' + # a hack: /assume/ that the calling write operation will not try # to write the fname and size, and update them in the db concurrently. # We cannot use a write() here, because we are already in one. cr.execute('UPDATE ir_attachment SET store_fname = %s, file_size = %s, index_content = %s, file_type = %s WHERE id = %s', - (store_fname, filesize, ustr(icont), mime, file_node.file_id)) + (store_fname, filesize, icont_u, mime, file_node.file_id)) file_node.content_length = filesize file_node.content_type = mime return True except Exception, e : - self._doclog.warning( "Couldn't save data:", exc_info=True) + self._doclog.warning("Couldn't save data:", exc_info=True) # should we really rollback once we have written the actual data? # at the db case (only), that rollback would be safe raise except_orm(_('Error at doc write!'), str(e))