[FIX] models: bad setup of inherited custom fields
Assume a custom field F is defined on model 'res.partner'. The setup of F may silently fail because of missing stuff. In that situation, setting up the field inherited from F on model 'res.users' should also silently fail. To reproduce the bug, install Invoicing, create a related custom field F on 'res.partner' with 'property_account_position_id.active', and install another module. Setting up F after loading module 'base' will fail because the field 'property_account_position_id' does not exist yet. The error is not caught by the inheritance of F on model 'res.users', and the installation crashes.
This commit is contained in:
+2
-1
@@ -277,6 +277,7 @@ class Field(MetaField('DummyField', (object,), {})):
|
||||
|
||||
'automatic': False, # whether the field is automatically created ("magic" field)
|
||||
'inherited': False, # whether the field is inherited (_inherits)
|
||||
'inherited_field': None, # the corresponding inherited field
|
||||
|
||||
'name': None, # name of the field
|
||||
'model_name': None, # name of the model of this field
|
||||
@@ -611,7 +612,7 @@ class Field(MetaField('DummyField', (object,), {})):
|
||||
@property
|
||||
def base_field(self):
|
||||
""" Return the base field of an inherited field, or ``self``. """
|
||||
return self.related_field.base_field if self.inherited else self
|
||||
return self.inherited_field.base_field if self.inherited_field else self
|
||||
|
||||
#
|
||||
# Company-dependent fields
|
||||
|
||||
+2
-1
@@ -2292,6 +2292,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
# - copy inherited fields iff their original field is copied
|
||||
fields[name] = field.new(
|
||||
inherited=True,
|
||||
inherited_field=field,
|
||||
related=(parent_field, name),
|
||||
related_sudo=False,
|
||||
copy=field.copy,
|
||||
@@ -2409,7 +2410,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
try:
|
||||
field.setup_full(self)
|
||||
except Exception:
|
||||
if not self.pool.loaded and field.manual:
|
||||
if not self.pool.loaded and field.base_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.
|
||||
|
||||
Reference in New Issue
Block a user