method-required-super (ODW8106)
Preview (since 0.16.2.1) · Related issues · View source
Derived from the odoo linter.
This rule is unstable and in preview. The --preview flag is required for use.
What it does
Checks that common Odoo ORM methods (create, write, unlink, init, ...) call
super() somewhere in their body.
Why is this bad?
Overriding one of these methods without calling super() usually means the base
implementation (and any other module's override in the resolution order) never
runs, silently breaking the inheritance chain.
init is reported only on a class that carries _inherit or _inherits, because that
is where the model being extended already has an init of its own building indexes and
SQL constraints. sale.order.line inherits analytic.mixin, whose
init creates the sale_order_line_analytic_distribution_accounts_gin_index GIN index,
so a module overriding init on sale.order.line without chaining silently drops it. A
class declaring only _name defines a brand-new model, where models.Model.init does
nothing and the call is not required.
Example
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def init(self):
self.env.cr.execute("CREATE INDEX ...")
Use instead:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def init(self):
# analytic.mixin builds its analytic_distribution gin index in init() too;
# without the super() call it never runs for sale_order_line.
super().init()
self.env.cr.execute("CREATE INDEX ...")
Options
The default is the ORM and test methods whose override must chain.
References
analytic.mixin.init— creates theanalytic_distributionGIN index, and chains tosuper().init()itself.sale.order.line— its_inherit = ['analytic.mixin']is what puts thatinitin the resolution order of every module extending the model.