no-search-all (W8163)#

search([]) without a limit loads every record.

What it does#

Reports search() and search_read() with an empty domain and no limit or count inside model methods, including a domain variable assigned [] in the same method and never extended before the call.

Why is this bad?#

The query loads every record of the model, which gets slower as the database grows and can exhaust the worker’s memory.

Example#

partners = self.env["res.partner"].search([])

Use instead: add a domain, or a limit when any record will do.

Configuration#

Models whose number of records is small by design can be allowed:

[tool.odoo-lint.rules.no-search-all]
# res.company: one per company (13 in production). machine.machine is not
# listed: 1,554 records and growing.
bounded-models = ["res.company"]

A search on self.env["res.company"] (also after .sudo(), .with_context(...) and the like) is then not reported.

Count the records in a production database before listing a model, and note the reason next to it: the name does not tell. Two models of the same module can differ by orders of magnitude, and a model that is small today may not stay small. There is no default list for that reason.