Skip to content

no-raise-unlink (ODOO039)

Preview (since 0.16.2.2) · 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 for raise statements inside unlink() methods of Odoo models.

Why is this bad?

Since Odoo 15.0, deletion constraints belong in an @api.ondelete-decorated method; raising inside unlink itself breaks batch deletions from other modules that expect unlink to succeed after their own @api.ondelete checks passed.

Example

def unlink(self):
    if self.state == "done":
        raise UserError("Cannot delete a done record")
    return super().unlink()

Use instead:

@api.ondelete(at_uninstall=False)
def _unlink_except_done(self):
    if self.state == "done":
        raise UserError("Cannot delete a done record")