[FIX] models: do not prefetch fields while the model schema is created

The following case has shown the issue: extend the model `res.company` by
adding at least two fields F and G, where F has a default value defined as:

    lambda self: self.env.user.company_id.name

If the column F is created before G in the database, the existing records will
be filled with the default value of F.  When the default value is computed, the
field `name` from a `res.company` is read, and other fields are prefetched,
including G.  This operation fails, because G does not exist in database yet!
This commit is contained in:
Raphael Collet 2015-04-02 15:48:38 +02:00
parent ad55981b4b
commit 9a365e83e7
1 changed files with 6 additions and 2 deletions

View File

@ -2422,8 +2422,12 @@ class BaseModel(object):
"""
self._foreign_keys = set()
raise_on_invalid_object_name(self._name)
if context is None:
context = {}
# This prevents anything called by this method (in particular default
# values) from prefetching a field for which the corresponding column
# has not been added in database yet!
context = dict(context or {}, prefetch_fields=False)
store_compute = False
stored_fields = [] # new-style stored fields with compute
todo_end = []