From d9cb0671a67038c4e9368641011be4595dbdc9ae Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Fri, 2 Dec 2022 11:13:18 +0000 Subject: [PATCH] [FIX] core: converse existing context in JSON-RPC Define the following controller: @route('/get-context', auth='public', type='json', website=True): return request.env.context Access that route via JSON-RPC providing a context: this._rpc({ route: '/get-context', params: { context: {"a": 1} } }) Since httpocalypse, it replaces the context entirely instead of updating it. i.e. before you would get along those lines: {"a": 1, "lang": "en_US", "tz": "Europe/Brussels", "uid": 2} but since you get instead (and that's wrong): {"a": 1} Note that after this commit, this merging-context behavior will be the same whether or not website=True is defined (while it was only there for website=True before). Discovered via opw-2885948 X-original-commit: 7887cfc3f177d9e64f008aabb8bd710f54024dea Part-of: odoo/odoo#107179 --- odoo/addons/test_http/tests/test_echo_reply.py | 4 +++- odoo/http.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/odoo/addons/test_http/tests/test_echo_reply.py b/odoo/addons/test_http/tests/test_echo_reply.py index fe9c4458280..291c5f9aee9 100644 --- a/odoo/addons/test_http/tests/test_echo_reply.py +++ b/odoo/addons/test_http/tests/test_echo_reply.py @@ -170,4 +170,6 @@ class TestHttpEchoReplyJsonWithDB(TestHttpBase): }) res = self.db_url_open("/test_http/echo-json-context", data=payload, headers=CT_JSON) self.assertEqual(res.status_code, 200) - self.assertEqual(res.text, '{"jsonrpc": "2.0", "id": 0, "result": {"name": "Thor"}}') + self.assertEqual(res.text, '{"jsonrpc": "2.0", "id": 0, "result": ' + f'{{"lang": "en_US", "tz": false, "uid": {self.jackoneill.id}, "name": "Thor"}}' + '}') diff --git a/odoo/http.py b/odoo/http.py index 1d1fa290b94..20f286136c8 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -1798,7 +1798,7 @@ class JsonRPCDispatcher(Dispatcher): self.request.params = dict(self.jsonrequest.get('params', {}), **args) ctx = self.request.params.pop('context', None) if ctx is not None and self.request.db: - self.request.update_env(context=ctx) + self.request.update_context(**ctx) if self.request.db: result = self.request.registry['ir.http']._dispatch(endpoint)