details:   https://code.tryton.org/tryton/commit/12063a1d6d42
branch:    7.6
user:      Cédric Krier <[email protected]>
date:      Wed Nov 12 14:56:34 2025 +0100
description:
        Include the traceback only in RPC responses in development mode

        Closes #14354
        (grafted from 8693a06919f2ceac1aa9f36ab6069325198ec94b)
diffstat:

 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(-)

diffs (60 lines):

diff -r a065ade03bbb -r 12063a1d6d42 trytond/CHANGELOG
--- a/trytond/CHANGELOG Mon Nov 17 10:28:49 2025 +0100
+++ b/trytond/CHANGELOG Wed Nov 12 14:56:34 2025 +0100
@@ -1,3 +1,4 @@
+* Include the traceback only in RPC responses in development mode (issue14354)
 * Enforce access check in HTML editor route (issue14364)
 
 Version 7.6.10 - 2025-11-02
diff -r a065ade03bbb -r 12063a1d6d42 trytond/bin/trytond
--- a/trytond/bin/trytond       Mon Nov 17 10:28:49 2025 +0100
+++ b/trytond/bin/trytond       Wed Nov 12 14:56:34 2025 +0100
@@ -74,6 +74,7 @@
                     '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 -r a065ade03bbb -r 12063a1d6d42 trytond/trytond/protocols/jsonrpc.py
--- a/trytond/trytond/protocols/jsonrpc.py      Mon Nov 17 10:28:49 2025 +0100
+++ b/trytond/trytond/protocols/jsonrpc.py      Wed Nov 12 14:56:34 2025 +0100
@@ -166,7 +166,9 @@
                 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 -r a065ade03bbb -r 12063a1d6d42 trytond/trytond/wsgi.py
--- a/trytond/trytond/wsgi.py   Mon Nov 17 10:28:49 2025 +0100
+++ b/trytond/trytond/wsgi.py   Wed Nov 12 14:56:34 2025 +0100
@@ -58,6 +58,7 @@
                 })
         self.protocols = [JSONProtocol, XMLProtocol]
         self.error_handlers = []
+        self.dev = False
 
     def route(self, string, methods=None, defaults=None):
         def decorator(func):
@@ -106,10 +107,11 @@
         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)

Reply via email to