[IMP] models: move prefetching of records back to method _prefetch_field
authorRaphael Collet <rco@openerp.com>
Tue, 19 Aug 2014 13:45:18 +0000 (15:45 +0200)
committerRaphael Collet <rco@openerp.com>
Fri, 22 Aug 2014 12:42:20 +0000 (14:42 +0200)
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
openerp/models.py

index 5ef3d15..ca572b9 100644 (file)
@@ -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)
index 5e319a7..d8d0dc2 100644 (file)
@@ -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(