From cfb5f8f7cfabe1e3dcb107eea2105a221a6b0e5e Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 27 Jun 2013 13:49:16 +0200 Subject: [PATCH] [FIX] rml2pdf: prevent report expression evaluation from crashing report completely This is a revert of revision 4838 revid:vmt@openerp.com-20130327160420-pxw83283xcro1h52 which was based on the idea that we ought to fix broken reports rather than hide their problems. This is correct but is blocking users even for tiny details in the report, so it is better to attempt generating the output anyway, and log an obvious error so we have all the data needed to fix the report. bzr revid: odo@openerp.com-20130627114916-d5p1qjye9tsgammj --- openerp/report/render/rml2pdf/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openerp/report/render/rml2pdf/utils.py b/openerp/report/render/rml2pdf/utils.py index ae70cd46c94..6fce8106b49 100644 --- a/openerp/report/render/rml2pdf/utils.py +++ b/openerp/report/render/rml2pdf/utils.py @@ -116,10 +116,13 @@ def _process_text(self, txt): result += tools.ustr(self.localcontext.get('translate', lambda x:x)(to_translate)) if sps: txt = None - expr = sps.pop(0) - txt = eval(expr, self.localcontext) - if txt and isinstance(txt, basestring): - txt = tools.ustr(txt) + try: + expr = sps.pop(0) + txt = eval(expr, self.localcontext) + if txt and isinstance(txt, basestring): + txt = tools.ustr(txt) + except Exception: + _logger.error("Failed to evaluate expression [[ %s ]] with context %r while rendering report, ignored.", expr, self.localcontext) if isinstance(txt, basestring): result += txt elif txt and (txt is not None) and (txt is not False):