OD126 python-api-removed¶
The module uses a Python API its series removed.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Deprecation | Error | saas~13.1 and later | no |
What it reports¶
A form of the Python API that fails in the module's series, while OD125 reports one that Odoo accepts and ignores:
| Form | Removed from | Use instead |
|---|---|---|
sudo(user) |
saas~15.3 | with_user(user) |
message_post(subtype=) |
saas~13.1 | subtype_xmlid= |
flush(), recompute() on a recordset |
saas~16.2 | flush_model(), flush_recordset() or self.env.flush_all() |
invalidate_cache() on a recordset |
saas~16.2 | invalidate_model(), invalidate_recordset() or self.env.invalidate_all() |
refresh() on a recordset |
saas~16.2 | self.env.invalidate_all() |
user_has_groups() |
saas~17.2 | self.env.user.has_groups() |
numbercall written on ir.cron |
saas~17.3 | active=False, or _trigger() for one more run; for a negative number, nothing, as a cron repeats until deactivated |
doall written on ir.cron |
saas~17.3 | nothing: remove it |
check_access_rights(), check_access_rule() |
saas~19.1 | check_access(), or has_access() for check_access_rights() given raise_exception=False |
read_group() |
saas~19.1, before 20.0 | _read_group() |
an override of read_group() in a model class |
saas~19.1 | an override of _read_group() or formatted_read_group() |
read_group(fields=, orderby=, lazy=) |
20.0 | read_group(domain, groupby, aggregates, order=) |
an import of odoo.osv |
saas~19.1 | odoo.fields.Domain |
request.jsonrequest |
saas~15.3 | request.get_json_data(), request.dispatcher.jsonrequest on saas~15.3 |
The forms read as OD125 describes, which reports most of them as warnings in the
series before. An import in the body of a try whose handler catches ImportError is a fallback
for the series without the package, so it is not reported here. The ir.cron fields count as keys
of the literal dict that create() or write() gives a recordset of ir.cron, such as
self.env["ir.cron"].sudo(), or of the first dict of a literal list that names the field.
Why it matters¶
A removed method, attribute or package raises AttributeError or ImportError where the code
runs, and an import at the top of a file stops the module from loading at all. From saas~15.3
sudo() asserts that its argument is a flag, and from saas~13.1 message_post() raises on
subtype=. From saas~17.3 ir.cron has no numbercall or doall field, so create() and
write() raise on them.
20.0 defines read_group() again, with another signature, so the old call is reported until
saas~19.4, and on 20.0 only when it passes a keyword the new signature lacks. An override of it
stays an error on 20.0, which declares the new method final.
Example¶
class ResPartner(models.Model):
_inherit = "res.partner"
def _notify_as(self, user):
return self.sudo(user).message_post(body="Account updated", subtype="mail.mt_note")
On 18.0 the call fails on sudo()'s assertion, and message_post() would raise on subtype=
next.
class ResPartner(models.Model):
_inherit = "res.partner"
def _notify_as(self, user):
return self.with_user(user).message_post(body="Account updated", subtype_xmlid="mail.mt_note")
Fixing¶
oscn check --fix rewrites sudo(user) given only the user to with_user(user). The other forms
are left to rewrite by hand.
See fixing findings.