[FIX] filtering out of records which shouldn't be fetched/prefetched
authorXavier Morel <xmo@openerp.com>
Fri, 11 Jul 2014 12:07:05 +0000 (14:07 +0200)
committerXavier Morel <xmo@openerp.com>
Fri, 11 Jul 2014 12:07:05 +0000 (14:07 +0200)
A todo would only filter out records selectioned by the same field's caching,
it should filter out on the whole prefetching selection or an other field
could/would just add it back to the set of records to fetch (and lead to Bad
Things).

Note: this probably deserves a test somehow, but I'm not quite sure how the
todos thing works so...

openerp/models.py

index 73b0981..f48aa5b 100644 (file)
@@ -3177,10 +3177,12 @@ class BaseModel(object):
                 }
 
         empty = self.browse()
-        records = self.browse(set(itertools.chain.from_iterable(
-            (self._in_cache_without(field) - self.env.todo.get(field, empty)).ids
-            for field in (self._fields[name] for name in field_names)
-        )))
+        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)
 
         result = []
         for sub_ids in cr.split_for_in_conditions(records.ids):