[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:
parent
ad55981b4b
commit
9a365e83e7
|
@ -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 = []
|
||||
|
|
Loading…
Reference in New Issue