[FIX] orm: avoir errors reading twice a field
authorMartin Trigaux <mat@openerp.com>
Thu, 12 Jun 2014 14:14:41 +0000 (16:14 +0200)
committerMartin Trigaux <mat@openerp.com>
Thu, 12 Jun 2014 14:14:41 +0000 (16:14 +0200)
_read_flat: remove duplicated fields in read call
get many2one: as False is instance of int, check the value of x first to avoid calling a name_get with a list of False

When we were reading twice a m2o field where at least one result is null, the first call to name_get would set the value to False instead of None and then accepted by the filter 'isinstance(x, (int,long))'

openerp/osv/fields.py
openerp/osv/orm.py

index 18aa3aa..4942136 100644 (file)
@@ -464,7 +464,7 @@ class many2one(_column):
         # we use uid=1 because the visibility of a many2one field value (just id and name)
         # must be the access right of the parent form and not the linked object itself.
         records = dict(obj.name_get(cr, SUPERUSER_ID,
-                                    list(set([x for x in res.values() if isinstance(x, (int,long))])),
+                                    list(set([x for x in res.values() if x and isinstance(x, (int,long))])),
                                     context=context))
         for id in res:
             if res[id] in records:
index 6e91ba4..1dbac53 100644 (file)
@@ -3694,6 +3694,8 @@ class BaseModel(object):
             return []
         if fields_to_read is None:
             fields_to_read = self._columns.keys()
+        else:
+            fields_to_read = list(set(fields_to_read))
 
         # all inherited fields + all non inherited fields for which the attribute whose name is in load is True
         fields_pre = [f for f in fields_to_read if