[FIX] models: fields_get() shall not return info about fields not set up yet
authorRaphael Collet <rco@openerp.com>
Mon, 6 Oct 2014 09:56:03 +0000 (11:56 +0200)
committerRaphael Collet <rco@openerp.com>
Mon, 6 Oct 2014 09:56:03 +0000 (11:56 +0200)
When processing data files during a module installation/upgrade, not all fields
are set up yet, in particular relational custom fields.  Make fields_get()
ignore those fields, so that views can be created/updated and validated,
provided they do not refer to those fields...

openerp/fields.py
openerp/models.py

index 6a2f0f7..3e0b2a3 100644 (file)
@@ -251,6 +251,7 @@ class Field(object):
     automatic = False           # whether the field is automatically created ("magic" field)
     inherited = False           # whether the field is inherited (_inherits)
     column = None               # the column interfaced by the field
+    setup_done = False          # whether the field has been set up
 
     name = None                 # name of the field
     type = None                 # type of the field (string)
@@ -346,7 +347,7 @@ class Field(object):
 
     def reset(self):
         """ Prepare `self` for a new setup. """
-        self._setup_done = False
+        self.setup_done = False
         # self._triggers is a set of pairs (field, path) that represents the
         # computed fields that depend on `self`. When `self` is modified, it
         # invalidates the cache of each `field`, and registers the records to
@@ -359,8 +360,8 @@ class Field(object):
             and other properties). This method is idempotent: it has no effect
             if `self` has already been set up.
         """
-        if not self._setup_done:
-            self._setup_done = True
+        if not self.setup_done:
+            self.setup_done = True
             self._setup(env)
 
     def _setup(self, env):
index 603096c..35e06db 100644 (file)
@@ -3042,6 +3042,8 @@ class BaseModel(object):
         for fname, field in self._fields.iteritems():
             if allfields and fname not in allfields:
                 continue
+            if not field.setup_done:
+                continue
             if field.groups and not recs.user_has_groups(field.groups):
                 continue
             res[fname] = field.get_description(recs.env)