diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-03-17 11:08:38 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-04-09 09:06:34 +0000 |
| commit | 1ecb0641efead9966faafb853c1e03138a49f111 (patch) | |
| tree | 594c2fd44c58960116f2f96b3846cd45bb4ae436 /odoo/addons/base/tests/test_xmlrpc.py | |
| parent | 4a1bd8fe79fea951ee53e77b170424fadbda9d5f (diff) | |
[FIX] core: calling read_group / name_search over xmlrpc
Also non-browser jsonrpc (as it goes through a similar process): for
internal performance reasons, name_search and read_group have been
converted to a *lazy* name_get, so the "display name" is not
unnecessarily computed.
However this is an issue for the RPC endpoints (/xmlrpc and /jsonrpc)
as they have no support for `lazy` and thus tend to blow up and / or
do the wrong thing when trying to output a lazy:
* xmlrpc has no way to handle lazy at all and straight blows up
* jsonrpc falls back to `json_default` so they try to stringify the
lazy, which might have worked except
*Problematically* both endpoints delegate the actual work to
`dispatch_rpc` which handles dispatching between various services and
ultimately creates a *new* cursor before calling model
methods (`object` service and `execute`/`execute_kw`).
This means by the time the result is serialized to be output, the
lazy's cursor has long been closed, and thus any access to an
unevaluated `lazy` errors out when trying to fetch the underlying
item.
This also means we can't just add a hook to serialize the lazy
in the xmlrpc marshaller, though we do have to do that. We *also* (for
both xmlrpc and jsonrpc) have to force evluation of lazy values before
our cursor is closed, meaning it has to be done right after the method
is invoked, iterating the entire response.
Related to task 2170343
closes odoo/odoo#49286
X-original-commit: e2b5a359c1d5eccbe725c1c3169b4130d7bca49b
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo/addons/base/tests/test_xmlrpc.py')
| -rw-r--r-- | odoo/addons/base/tests/test_xmlrpc.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/odoo/addons/base/tests/test_xmlrpc.py b/odoo/addons/base/tests/test_xmlrpc.py index 09ec01adfbb..aa4d9028d10 100644 --- a/odoo/addons/base/tests/test_xmlrpc.py +++ b/odoo/addons/base/tests/test_xmlrpc.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import odoo.tools from odoo.tests import common @@ -25,3 +26,41 @@ class TestXMLRPC(common.HttpCase): self.assertIsInstance(ids, list) ids = o.execute(db_name, self.admin_uid, 'admin', 'ir.model', 'search', [], {}) self.assertIsInstance(ids, list) + + def test_xmlrpc_read_group(self): + groups = self.xmlrpc_object.execute( + common.get_db_name(), self.admin_uid, 'admin', + 'res.partner', 'read_group', [], ['is_company', 'color'], ['parent_id'] + ) + + def test_xmlrpc_name_search(self): + self.xmlrpc_object.execute( + common.get_db_name(), self.admin_uid, 'admin', + 'res.partner', 'name_search', "admin" + ) + + def test_jsonrpc_read_group(self): + self._json_call( + common.get_db_name(), self.admin_uid, 'admin', + 'res.partner', 'read_group', [], ['is_company', 'color'], ['parent_id'] + ) + + def test_jsonrpc_name_search(self): + # well that's some sexy sexy call right there + self._json_call( + common.get_db_name(), + self.admin_uid, 'admin', + 'res.partner', 'name_search', 'admin' + ) + + def _json_call(self, *args): + self.opener.post("http://%s:%s/jsonrpc" % (common.HOST, odoo.tools.config['http_port']), json={ + 'jsonrpc': '2.0', + 'id': None, + 'method': 'call', + 'params': { + 'service': 'object', + 'method': 'execute', + 'args': args + } + }) |
