[IMP] http.py: do not inject context by default in JSON routes
Before this revision, when you pass `context` in the arguments of a JSON routes, this one gets automatically injected in the environment context. This is not the case for regular HTTP routes. It makes sense to propagate the context for the JSONRPC protocol, JSON routes used by the backend, such as `call_kw`, but it doesn't make sense to pass this context automatically for any other kind of routes, such as front-end routes or routes used by custom Javascript widgets. This change brings a more unified behavior for routes of types HTTP and JSON. In addition, most developers were not aware of this "feautre", that passing `context` in the arguments of a JSON route leaded to the injection of this context in the environment context. This is actually reflected by the diff size this changes required, only a dozens of routes needed to be adapted, to manually add the context in their route arguments and to inject it in their environment context. closes odoo/odoo#121726 X-original-commit: a7a5655631e6d5b05fd2ba3d0c80617aae6d9cfe Related: odoo/enterprise#41229 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
+2
-5
@@ -1897,13 +1897,13 @@ class JsonRPCDispatcher(Dispatcher):
|
||||
|
||||
Successful request::
|
||||
|
||||
--> {"jsonrpc": "2.0", "method": "call", "params": {"context": {}, "arg1": "val1" }, "id": null}
|
||||
--> {"jsonrpc": "2.0", "method": "call", "params": {"arg1": "val1" }, "id": null}
|
||||
|
||||
<-- {"jsonrpc": "2.0", "result": { "res1": "val1" }, "id": null}
|
||||
|
||||
Request producing a error::
|
||||
|
||||
--> {"jsonrpc": "2.0", "method": "call", "params": {"context": {}, "arg1": "val1" }, "id": null}
|
||||
--> {"jsonrpc": "2.0", "method": "call", "params": {"arg1": "val1" }, "id": null}
|
||||
|
||||
<-- {"jsonrpc": "2.0", "error": {"code": 1, "message": "End user error message.", "data": {"code": "codestring", "debug": "traceback" } }, "id": null}
|
||||
|
||||
@@ -1914,9 +1914,6 @@ class JsonRPCDispatcher(Dispatcher):
|
||||
raise BadRequest("Invalid JSON data") from exc
|
||||
|
||||
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_context(**ctx)
|
||||
|
||||
if self.request.db:
|
||||
result = self.request.registry['ir.http']._dispatch(endpoint)
|
||||
|
||||
Reference in New Issue
Block a user