From 50248f6b31de7c24e899c9c81354cfe07a078653 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 (grafted from 8693a06919f2ceac1aa9f36ab6069325198ec94b) --HG-- branch : 6.0 --- 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 2c7957bfb7..4babc24e92 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) Version 6.0.69 - 2025-11-02 diff --git a/trytond/bin/trytond b/trytond/bin/trytond index d1dddec5b9..62314e0c1f 100755 --- a/trytond/bin/trytond +++ b/trytond/bin/trytond @@ -66,6 +66,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 988d8b24ef..0a933e808c 100644 --- a/trytond/trytond/protocols/jsonrpc.py +++ b/trytond/trytond/protocols/jsonrpc.py @@ -169,7 +169,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 e8491ce48d..a621f006d8 100644 --- a/trytond/trytond/wsgi.py +++ b/trytond/trytond/wsgi.py @@ -65,6 +65,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): @@ -122,10 +123,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)