From cc1a046c9edfdcd5ea689c490722a7057a49cefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 13 Apr 2026 14:38:48 +0200 Subject: [PATCH] Test instances against the Response/Request classes from werkzeug It should be allowed to use the base classes instead of the custom derived of Tryton. Closes #14765 --- trytond/trytond/protocols/wrappers.py | 10 +++++----- trytond/trytond/wsgi.py | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/trytond/trytond/protocols/wrappers.py b/trytond/trytond/protocols/wrappers.py index abd529a23b..6937c078df 100644 --- a/trytond/trytond/protocols/wrappers.py +++ b/trytond/trytond/protocols/wrappers.py @@ -17,8 +17,8 @@ from werkzeug import exceptions from werkzeug.datastructures import Authorization from werkzeug.exceptions import abort from werkzeug.utils import redirect, send_file -from werkzeug.wrappers import Request as _Request -from werkzeug.wrappers import Response as _Response +from werkzeug.wrappers import Request as BaseRequest +from werkzeug.wrappers import Response as BaseResponse from trytond import backend, config, security from trytond.exceptions import RateLimitException, UserError, UserWarning @@ -84,7 +84,7 @@ def remove_auth_cookies(response, database): remove_cookie(response, database, TRYTON_SESSION_COOKIE) -class Request(_Request): +class Request(BaseRequest): view_args = None @@ -204,7 +204,7 @@ class Request(_Request): } -class Response(_Response): +class Response(BaseResponse): def get_json(self, force=False, silent=False): from .jsonrpc import JSONDecoder, json @@ -413,7 +413,7 @@ def user_application(name, json=True): response = func(request, *args, **kwargs) except (UserError, UserWarning) as e: raise JSONBadRequest(e) - if not isinstance(response, Response) and json: + if not isinstance(response, BaseResponse) and json: response = Response(json_.dumps(response, cls=JSONEncoder), content_type='application/json') return response diff --git a/trytond/trytond/wsgi.py b/trytond/trytond/wsgi.py index 63cba461de..d951a1bea0 100644 --- a/trytond/trytond/wsgi.py +++ b/trytond/trytond/wsgi.py @@ -30,7 +30,7 @@ except ImportError: from trytond import backend, config, security from trytond.protocols.jsonrpc import JSONProtocol from trytond.protocols.wrappers import ( - HTTPStatus, Request, Response, abort, exceptions) + BaseResponse, HTTPStatus, Request, Response, abort, exceptions) from trytond.protocols.xmlrpc import XMLProtocol from trytond.status import processing from trytond.tools import resolve, safe_join @@ -142,7 +142,7 @@ class TrytondWSGI(object): response = e for error_handler in self.error_handlers: rv = error_handler(self, request, e) - if isinstance(rv, Response): + if isinstance(rv, BaseResponse): response = rv return response @@ -205,12 +205,13 @@ class TrytondWSGI(object): with processing(request): data = self.dispatch_request(request) - if not isinstance(data, (Response, exceptions.HTTPException)): + if not isinstance( + data, (BaseResponse, exceptions.HTTPException)): response = self.make_response(request, data) else: response = data - if origin and isinstance(response, Response): + if origin and isinstance(response, BaseResponse): response.headers['Access-Control-Allow-Origin'] = origin response.headers['Vary'] = 'Origin' method = request.headers.get('Access-Control-Request-Method')