Skip to content

deprecated-osv-expression (ODW9502)

Preview (since 0.16.3.33) · Related issues · View source

Derived from the odoo linter.

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for uses of the odoo.osv.expression module, deprecated in Odoo 19.0 in favor of odoo.fields.Domain.

Why is this bad?

Every function of odoo.osv.expression raises a DeprecationWarning in 19.0, and importing odoo.osv at all raises one too. The whole package was then removed, so code still calling it fails to import on the versions that follow.

Example

from odoo.osv import expression

domain = expression.AND([domain, [("state", "=", "draft")]])

Use instead:

from odoo.fields import Domain

domain = Domain.AND([domain, [("state", "=", "draft")]])

Fix safety

The fix is marked unsafe because the two APIs do not return the same type: expression.AND returns a plain list, Domain.AND returns a Domain. The ORM takes either one, and Domain supports iteration, + and == against a list, but it has no len() and no indexing, so a caller that measures or subscripts the result changes meaning.

The now-unused from odoo.osv import expression is left in place; F401 reports it.