[FIX] fields: in computed fields, handle AccessError and MissingError
authorRaphael Collet <rco@openerp.com>
Thu, 11 Sep 2014 08:31:10 +0000 (10:31 +0200)
committerRaphael Collet <rco@openerp.com>
Thu, 11 Sep 2014 09:57:18 +0000 (11:57 +0200)
When computing a field on a recordset, a subset of the records may be missing
or forbidden by access rules.  In that case, evaluate the compute method record
by record, and mark failed records as such in cache.

openerp/fields.py

index 1af7283..8644232 100644 (file)
@@ -769,9 +769,13 @@ class Field(object):
         with records.env.do_in_draft():
             try:
                 self._compute_value(records)
-            except MissingError:
-                # some record is missing, retry on existing records only
-                self._compute_value(records.exists())
+            except (AccessError, MissingError):
+                # some record is forbidden or missing, retry record by record
+                for record in records:
+                    try:
+                        self._compute_value(record)
+                    except Exception as exc:
+                        record._cache[self.name] = FailedValue(exc)
 
     def determine_value(self, record):
         """ Determine the value of `self` for `record`. """
@@ -1664,6 +1668,6 @@ class Id(Field):
 
 # imported here to avoid dependency cycle issues
 from openerp import SUPERUSER_ID
-from .exceptions import Warning, MissingError
+from .exceptions import Warning, AccessError, MissingError
 from .models import BaseModel, MAGIC_COLUMNS
 from .osv import fields