[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
This commit is contained in:
committed by
qsm-odoo
parent
928d584f20
commit
d9cb0671a6
@@ -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"}}'
|
||||
'}')
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user