summaryrefslogtreecommitdiff
path: root/odoo/addons/base/controllers/rpc.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-03-17 11:08:38 +0000
committerXavier Morel <xmo@odoo.com>2020-04-09 09:06:34 +0000
commit1ecb0641efead9966faafb853c1e03138a49f111 (patch)
tree594c2fd44c58960116f2f96b3846cd45bb4ae436 /odoo/addons/base/controllers/rpc.py
parent4a1bd8fe79fea951ee53e77b170424fadbda9d5f (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/controllers/rpc.py')
-rw-r--r--odoo/addons/base/controllers/rpc.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/odoo/addons/base/controllers/rpc.py b/odoo/addons/base/controllers/rpc.py
index 405fd26c44d..930c3170e52 100644
--- a/odoo/addons/base/controllers/rpc.py
+++ b/odoo/addons/base/controllers/rpc.py
@@ -7,6 +7,7 @@ from werkzeug.wrappers import Response
from odoo.http import Controller, dispatch_rpc, request, route
from odoo.service import wsgi_server
from odoo.fields import Date, Datetime
+from odoo.tools import lazy
class OdooMarshaller(xmlrpc.client.Marshaller):
@@ -28,6 +29,11 @@ class OdooMarshaller(xmlrpc.client.Marshaller):
self.dump_unicode(value, write)
dispatch[date] = dump_date
+ def dump_lazy(self, value, write):
+ v = value._value
+ return self.dispatch[type(v)](self, v, write)
+ dispatch[lazy] = dump_lazy
+
# monkey-patch xmlrpc.client's marshaller
xmlrpc.client.Marshaller = OdooMarshaller