From 95dc47a24fef4c07ebdc0cd49ffdffdead328fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 12 Nov 2025 14:56:34 +0100 Subject: [PATCH] Include the traceback only in RPC responses in development mode Closes #14354 --- trytond/CHANGELOG | 1 + trytond/bin/trytond | 1 + trytond/trytond/protocols/jsonrpc.py | 4 +++- trytond/trytond/wsgi.py | 10 ++++++---- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 8118ef29b5..597861251a 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Include the traceback only in RPC responses in development mode (issue14354) * Enforce access check in HTML editor route (issue14364) * Add a clear cache method to the Database * Add sequence_reorder to model order diff --git a/trytond/bin/trytond b/trytond/bin/trytond index 3210d25e69..cf4c3b2d37 100755 --- a/trytond/bin/trytond +++ b/trytond/bin/trytond @@ -74,6 +74,7 @@ with commandline.pidfile(options): 'txt', 'html', 'xhtml']: path = os.path.join(info['directory'], '**', '*.' + ext) extra_files.extend(glob.glob(path, recursive=True)) + app.dev = options.dev if options.coroutine: from gevent.pywsgi import WSGIServer diff --git a/trytond/trytond/protocols/jsonrpc.py b/trytond/trytond/protocols/jsonrpc.py index 5e68ede280..359c1cab9e 100644 --- a/trytond/trytond/protocols/jsonrpc.py +++ b/trytond/trytond/protocols/jsonrpc.py @@ -172,7 +172,9 @@ class JSONProtocol: response['error'] = data.args elif isinstance(data, Exception): # report exception back to server - response['error'] = (str(data), data.__format_traceback__) + response['error'] = ( + str(data), + getattr(data, '__format_traceback__', '')) else: response['result'] = data else: diff --git a/trytond/trytond/wsgi.py b/trytond/trytond/wsgi.py index 237bf70175..b0013d3602 100644 --- a/trytond/trytond/wsgi.py +++ b/trytond/trytond/wsgi.py @@ -70,6 +70,7 @@ class TrytondWSGI(object): }) self.protocols = [JSONProtocol, XMLProtocol] self.error_handlers = [] + self.dev = False def route(self, string, methods=None, defaults=None): def decorator(func): @@ -132,10 +133,11 @@ class TrytondWSGI(object): except Exception as e: logger.debug( "Exception when processing %s", request, exc_info=True) - tb_s = ''.join(traceback.format_exception(*sys.exc_info())) - for path in sys.path: - tb_s = tb_s.replace(path, '') - e.__format_traceback__ = tb_s + if self.dev: + tb_s = ''.join(traceback.format_exception(*sys.exc_info())) + for path in sys.path: + tb_s = tb_s.replace(path, '') + e.__format_traceback__ = tb_s response = e for error_handler in self.error_handlers: rv = error_handler(self, request, e)