From 7acadc00c66bf8166f023b4eec662bf956799faa Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 13 Dec 2012 14:05:48 +0100 Subject: [PATCH] [FIX] unwarranted assumption that name_get(ids) and read(ids) will return the same records in the same order There is actually no such guarantee, neither name_get nor read guarantee they'll return records in input order, let alone in the same order as one another, and both are free to skip records as they see fit (kinda). => convert the name_get result to a dict, and then fill in the display_name for each record returned by read() using get() bzr revid: xmo@openerp.com-20121213130548-x1h6czyru5nc6wwm --- addons/web/controllers/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index fe23e99a5a1..d4fe2d79acc 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1059,14 +1059,15 @@ class DataSet(openerpweb.Controller): def _call_kw(self, req, model, method, args, kwargs): # Temporary implements future display_name special field for model#read() - if method == 'read' and kwargs.get('context') and kwargs['context'].get('future_display_name'): + if method == 'read' and kwargs.get('context', {}).get('future_display_name'): if 'display_name' in args[1]: - names = req.session.model(model).name_get(args[0], **kwargs) + names = dict(req.session.model(model).name_get(args[0], **kwargs)) args[1].remove('display_name') - r = getattr(req.session.model(model), method)(*args, **kwargs) - for i in range(len(r)): - r[i]['display_name'] = names[i][1] or "%s#%d" % (model, names[i][0]) - return r + records = req.session.model(model).read(*args, **kwargs) + for record in records: + record['display_name'] = \ + names.get(record['id']) or "%s#%d" % (model, (record['id'])) + return records return getattr(req.session.model(model), method)(*args, **kwargs)