From e6fe291bde0d6119f82da2a9c189fac74a28d1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 18 Apr 2024 19:28:04 +0200 Subject: [PATCH] Prevent to get user_id from request without view_args If user_id is accessed before view_args has been setup, we should not cache `None` as value but instead raise an exception. The `user_id` may be accessed before the mapping if the request is logged because the representation of the request used the `rpc_method` which needs to parse the request data. But since 1923117e935d parsing compressed content is only allowed for request with `user_id`. So we can no more include the `rpc_method` is the request has not yet been mapped and so it has a `view_args`. Closes #13203 (grafted from 0630029c1d5a0a2c7bd45086957f2e0fbed4c427) --HG-- branch : 6.0 --- trytond/trytond/protocols/wrappers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/trytond/trytond/protocols/wrappers.py b/trytond/trytond/protocols/wrappers.py index 9928a6704a..2b9a847049 100644 --- a/trytond/trytond/protocols/wrappers.py +++ b/trytond/trytond/protocols/wrappers.py @@ -44,7 +44,8 @@ class Request(_Request): args.append(self.remote_addr) args.append("'%s'" % url) args.append("[%s]" % self.method) - args.append("%s" % (self.rpc_method or '')) + if self.view_args: + args.append("%s" % (self.rpc_method or '')) except Exception: args.append("(invalid WSGI environ)") return "<%s %s>" % ( @@ -91,8 +92,7 @@ class Request(_Request): @cached_property def user_id(self): - if not self.view_args: - return None + assert self.view_args is not None database_name = self.view_args.get('database_name') if not database_name: return None