From dd6cd1a82f3e0e24fc5cc5b62811d1e5d65d5dfc Mon Sep 17 00:00:00 2001 From: niyasraphy Date: Sat, 26 Aug 2023 07:53:01 +0000 Subject: [PATCH] [FIX] base: traceback after enabling profiling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit before this commit, if profiling is enabled in the db, and on trying to validate a sale order, a traceback is shown * enable profiling * confirm a quotation traceback: Failed to render QWeb template :

introduced in: https://github.com/odoo/odoo/commit/016f26a9315c693bdeb894725898c2cf725d8989 here the options['ref'] is coming as the email template body and it is failing on try to do int of options['ref'] after this commit, no traceback wont be shown on confirming sale order, when profiling is enabled closes odoo/odoo#138357 X-original-commit: 01548aff72b031389a7563948bb12bc3abb07bfc Signed-off-by: Rémy Voet (ryv) --- odoo/addons/base/models/ir_qweb.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/odoo/addons/base/models/ir_qweb.py b/odoo/addons/base/models/ir_qweb.py index 0343ac3bc47..f7a3b11e4b8 100644 --- a/odoo/addons/base/models/ir_qweb.py +++ b/odoo/addons/base/models/ir_qweb.py @@ -366,6 +366,7 @@ structure. """ import base64 +import contextlib import fnmatch import io import logging @@ -623,10 +624,16 @@ class IrQWeb(models.AbstractModel): # generate the template functions and the root function name def generate_functions(): code, options, def_name = self._generate_code(template) - profile_options = { - 'ref': options.get('ref') and int(options['ref']) or None, - 'ref_xml': options.get('ref_xml') and str(options['ref_xml']) or None, - } if self.env.context.get('profile') else None + if self.env.context.get('profile'): + ref_value = None + with contextlib.suppress(ValueError, TypeError): + ref_value = int(options.get('ref')) + profile_options = { + 'ref': ref_value, + 'ref_xml': options.get('ref_xml') and str(options['ref_xml']) or None, + } + else: + profile_options = None code = '\n'.join([ "def generate_functions():", " template_functions = {}",