From 6e73a311468fb5bcebb5bbe93715ba585d07f4c3 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 8 Jul 2015 19:19:28 +0200 Subject: [PATCH] [FIX] base: ir.qweb: fault tolerant save of assets. Do not fail if an asset cannot be cached into the database. --- openerp/addons/base/ir/ir_qweb.py | 51 +++++++++++++++++++------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index f74170de46c..3d7c67cb6e3 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -20,6 +20,7 @@ import babel.dates import werkzeug from lxml import etree, html from PIL import Image +import psycopg2 import openerp.http import openerp.tools @@ -1257,16 +1258,21 @@ class AssetsBundle(object): ira = self.registry['ir.attachment'] url_prefix = '/web/%s/%s/' % (type, self.xmlid) # Invalidate previous caches - oids = ira.search(self.cr, openerp.SUPERUSER_ID, [('url', '=like', url_prefix + '%')], context=self.context) - if oids: - ira.unlink(self.cr, openerp.SUPERUSER_ID, oids, context=self.context) - url = url_prefix + self.version - ira.create(self.cr, openerp.SUPERUSER_ID, dict( + try: + with self.cr.savepoint(): + domain = [('url', '=like', url_prefix + '%')] + oids = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context) + if oids: + ira.unlink(self.cr, openerp.SUPERUSER_ID, oids, context=self.context) + url = url_prefix + self.version + ira.create(self.cr, openerp.SUPERUSER_ID, dict( datas=content.encode('utf8').encode('base64'), type='binary', name=url, url=url, ), context=self.context) + except psycopg2.Error: + pass def css_message(self, message): return """ @@ -1504,21 +1510,26 @@ class SassAsset(StylesheetAsset): def to_html(self): if self.url: - ira = self.registry['ir.attachment'] - url = self.html_url % self.url - domain = [('type', '=', 'binary'), ('url', '=', self.url)] - ira_id = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context) - if ira_id: - # TODO: update only if needed - ira.write(self.cr, openerp.SUPERUSER_ID, [ira_id], {'datas': self.content}, context=self.context) - else: - ira.create(self.cr, openerp.SUPERUSER_ID, dict( - datas=self.content.encode('utf8').encode('base64'), - mimetype='text/css', - type='binary', - name=url, - url=url, - ), context=self.context) + try: + ira = self.registry['ir.attachment'] + url = self.html_url % self.url + domain = [('type', '=', 'binary'), ('url', '=', self.url)] + with self.cr.savepoint(): + ira_id = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context) + if ira_id: + # TODO: update only if needed + ira.write(self.cr, openerp.SUPERUSER_ID, [ira_id], {'datas': self.content}, + context=self.context) + else: + ira.create(self.cr, openerp.SUPERUSER_ID, dict( + datas=self.content.encode('utf8').encode('base64'), + mimetype='text/css', + type='binary', + name=url, + url=url, + ), context=self.context) + except psycopg2.Error: + pass return super(SassAsset, self).to_html() def get_source(self):