OD119 override-drops-result¶
A create(), write() or copy() override calls super() but returns nothing.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Error | all | no |
What it reports¶
A create, write or copy method of a model class that calls the same method through super()
and has no return with a value: no return at all, or only a bare return or return None. A
return in a nested function or class is that function's, so it does not count. Likewise a
super() call in the body of a class defined inside the method does not count, while one in a
nested function does. The finding is at the method's name.
Why it matters¶
The ORM's create() returns the new records, copy() the copies, and write() returns True, and
every caller gets what the last override in the chain returns. An override that calls super()
and drops its result returns None instead: the records are created, but Odoo's own
name_create() then reads the id of None and raises AttributeError, as does any code that
uses the record create() or copy() gives it, and a caller that tests what write() returns
takes the wrong branch. Return what super() returns.
An override that never calls super() is reported by OD105 instead.
Example¶
class ResPartner(models.Model):
_inherit = "res.partner"
def write(self, vals):
if vals.get("email"):
vals["email"] = vals["email"].strip().lower()
super().write(vals)
class ResPartner(models.Model):
_inherit = "res.partner"
def write(self, vals):
if vals.get("email"):
vals["email"] = vals["email"].strip().lower()
return super().write(vals)