summaryrefslogtreecommitdiff
path: root/odoo/tools/date_utils.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/tools/date_utils.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/tools/date_utils.py')
-rw-r--r--odoo/tools/date_utils.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/odoo/tools/date_utils.py b/odoo/tools/date_utils.py
index c26817b3850..9d934448e30 100644
--- a/odoo/tools/date_utils.py
+++ b/odoo/tools/date_utils.py
@@ -4,8 +4,9 @@ import calendar
from datetime import date, datetime, time
import pytz
from dateutil.relativedelta import relativedelta
-from . import ustr
+from . import ustr
+from .func import lazy
def get_month(date):
''' Compute the month dates range on which the 'date' parameter belongs to.
@@ -198,16 +199,17 @@ def subtract(value, *args, **kwargs):
"""
return value - relativedelta(*args, **kwargs)
-
def json_default(obj):
"""
Properly serializes date and datetime objects.
"""
from odoo import fields
+ if isinstance(obj, datetime):
+ return fields.Datetime.to_string(obj)
if isinstance(obj, date):
- if isinstance(obj, datetime):
- return fields.Datetime.to_string(obj)
return fields.Date.to_string(obj)
+ if isinstance(obj, lazy):
+ return obj._value
return ustr(obj)