diff options
| author | Raphael Collet <rco@odoo.com> | 2020-11-05 11:13:29 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-11-09 12:12:08 +0000 |
| commit | 34e5e8717f8fe428958ce7e7960713f44c34060f (patch) | |
| tree | fb2d5b08500821889c935b4ef5667bd7fba4d1ed | |
| parent | 426a4306c911de2a47bd804dde0d67aa19a22b67 (diff) | |
[FIX] core: use 'x_name' as _rec_name only on custom models
This fixes a very obscure bug that happens on workers serving multiple
databases. Consider two databases A and B with the same model M, that
does not have a field 'name', but has a custom field 'x_name' only on
database A. The bug can be reproduced with the module 'account' and its
model 'account.register.payments'.
Assume the server loads a registry for database A. In that registry,
the model M uses 'x_name' as its _rec_name, and the field 'display_name'
on model M determines its dependencies to be the field 'x_name'.
Now assume the server load a registry for database B. In that registry,
the model M has no _rec_name. However, an optimization reuses the field
'display_name' for the model M on the registry of A. The field's
attribute 'depends' is equal to the tuple ('x_name',). When the ORM
tries to resolve the field's dependencies, it does not find the field
'x_name' on M and crashes.
In order to avoid this situation, we forbid the usage of 'x_name' as
_rec_name on non-custom models.
OPW 2349238
closes odoo/odoo#61531
X-original-commit: 731e676fa8a9f7bdc6a66056c124c3b39a0800ad
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
| -rw-r--r-- | odoo/fields.py | 6 | ||||
| -rw-r--r-- | odoo/models.py | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index dfdd203c490..04dddd4013c 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -629,7 +629,11 @@ class Field(MetaField('DummyField', (object,), {})): # recomputations of fields on transient models break - field = Model._fields[fname] + try: + field = Model._fields[fname] + except KeyError: + msg = "Field %s cannot find dependency %r on model %r." + raise ValueError(msg % (self, fname, model_name)) if field is self and index: self.recursive = True diff --git a/odoo/models.py b/odoo/models.py index affe6cf0cff..f607c92c6fc 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -2805,7 +2805,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): "Invalid _rec_name=%r for model %r" % (cls._rec_name, cls._name) elif 'name' in cls._fields: cls._rec_name = 'name' - elif 'x_name' in cls._fields: + elif cls._custom and 'x_name' in cls._fields: cls._rec_name = 'x_name' # 6. determine and validate active_name |
