From 97256fa1fba6c7d3d02962b5948158d17852cf43 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 19 Aug 2014 15:45:18 +0200 Subject: [PATCH] [IMP] models: move prefetching of records back to method _prefetch_field The selection of records in cache for prefetching was moved to method _read_from_database() by xmo at rev 785018cc in order to fix an access right bug. But this introduced an issue: to explicitly avoid prefetching, you should use read() instead of browsing records. We revert the change by xmo, without reintroducing the bug (which apparently was fixed by another way). --- addons/calendar/calendar.py | 6 ------ openerp/models.py | 16 ++++------------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index 5ef3d15da91..ca572b91e32 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -1581,12 +1581,6 @@ class calendar_event(osv.Model): select = [ids] else: select = ids - - # FIXME: find a better way to not push virtual ids in the cache - # (leading to their prefetching and ultimately a type error when - # postgres tries to convert '14-3489274297' to an integer) - self.invalidate_cache(cr, uid, context=context) - select = map(lambda x: (x, calendar_id2real_id(x)), select) result = [] real_data = super(calendar_event, self).read(cr, uid, [real_id for calendar_id, real_id in select], fields=fields2, context=context, load=load) diff --git a/openerp/models.py b/openerp/models.py index 5e319a7ef20..d8d0dc2ad4a 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -3122,7 +3122,7 @@ class BaseModel(object): instance) for `self` in cache. """ # fetch the records of this model without field_name in their cache - records = self + records = self._in_cache_without(field) # by default, simply fetch field fnames = {field.name} @@ -3198,16 +3198,8 @@ class BaseModel(object): 'order': self._parent_order or self._order, } - empty = self.browse() - prefetch = set() - todo = set() - for field in (self._fields[name] for name in field_names): - prefetch.update(self._in_cache_without(field).ids) - todo.update(self.env.todo.get(field, empty).ids) - records = self.browse(prefetch - todo | set(self.ids)) - result = [] - for sub_ids in cr.split_for_in_conditions(records.ids): + for sub_ids in cr.split_for_in_conditions(self.ids): cr.execute(query, [tuple(sub_ids)] + rule_params) result.extend(cr.dictfetchall()) @@ -3280,9 +3272,9 @@ class BaseModel(object): # store failed values in cache for the records that could not be read fetched = self.browse(ids) - missing = records - fetched + missing = self - fetched if missing: - extras = fetched - records + extras = fetched - self if extras: raise AccessError( _("Database fetch misses ids ({}) and has extra ids ({}), may be caused by a type incoherence in a previous request").format(