[FIX] models: partial loading of manual fields

Related and function manual fields may not be loadable during initial
setup (partial=True) due to dependencies being not loaded. Ignore
theses fields during partial loading.
This commit is contained in:
Christophe Simonis
2016-04-11 14:52:42 +02:00
parent a445fc996b
commit 87d160a742
2 changed files with 18 additions and 3 deletions
+17 -2
View File
@@ -3034,18 +3034,33 @@ class BaseModel(object):
cls._setup_done = True
@api.model
def _setup_fields(self):
def _setup_fields(self, partial):
""" Setup the fields, except for recomputation triggers. """
cls = type(self)
# set up fields, and determine their corresponding column
cls._columns = {}
bad_fields = []
for name, field in cls._fields.iteritems():
field.setup_full(self)
try:
field.setup_full(self)
except Exception:
if partial and field.manual:
# Something goes wrong when setup a manual field.
# This can happen with related fields using another manual many2one field
# that hasn't been loaded because the comodel does not exist yet.
# This can also be a manual function field depending on not loaded fields yet.
bad_fields.append(name)
continue
raise
column = field.to_column()
if column:
cls._columns[name] = column
for name in bad_fields:
del cls._fields[name]
delattr(cls, name)
# map each field to the fields computed with the same method
groups = defaultdict(list)
for field in cls._fields.itervalues():
+1 -1
View File
@@ -197,7 +197,7 @@ class Registry(Mapping):
model._setup_base(cr, SUPERUSER_ID, partial)
for model in self.models.itervalues():
model._setup_fields(cr, SUPERUSER_ID)
model._setup_fields(cr, SUPERUSER_ID, partial)
for model in self.models.itervalues():
model._setup_complete(cr, SUPERUSER_ID)