From a152c536b7467d689ae4e501777ff5d431a1ccae Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Wed, 25 Nov 2020 13:20:30 +0000 Subject: [PATCH] [FIX] fields: Better error for invalid @depends Create a model as follow: class FooModel(models.Model): _name = 'foo' bar = fields.Char(compute="compute_bar") @depends('bazz') # wrong dependency, bazz does not exist def compute_bar(self): for rec in self: rec.bar = "Babar raconte des beaux bobards." Uppon -u foo_module, a ValueError is rose for the invalid dependency with the following message: > Field foo.bar cannot find dependency bazz on model foo. We had feedback the error message was not very clear to some users, the new error message is: > Wrong @depends on 'compute_bar' (compute method of field foo.bar). > Dependency field 'bazz' not found in model foo. closes odoo/odoo#62328 Task: 2366612 Signed-off-by: Julien Castiaux --- odoo/fields.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/odoo/fields.py b/odoo/fields.py index e1417bb6017..99bb26f5581 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -637,8 +637,10 @@ class Field(MetaField('DummyField', (object,), {})): try: field = Model._fields[fname] except KeyError: - msg = "Field %s cannot find dependency %r on model %r." - raise ValueError(msg % (self, fname, model_name)) + raise ValueError( + f"Wrong @depends on '{self.compute}' (compute method of field {self}). " + f"Dependency field '{fname}' not found in model {model_name}." + ) if field is self and index: self.recursive = True