Batch computes survive forbidden records in prefetch
When the prefetch set held records the user can't read, non-stored computes fell back to one query per record. They now stay batched, which matters for portal and public pages.
When the prefetch set held records the user can't read, non-stored computes fell back to one query per record. They now stay batched, which matters for portal and public pages.
| Branch | Pull request | Commit |
|---|---|---|
| 20.0 | odoo/odoo#293541 ↗ | 2401b31a7c ↗ |
[FIX] orm: keep batch computation when prefetch has forbidden records A non-stored computed field read on the visible records of a one2many is computed in batch on the whole prefetch set, which can include records the user cannot read. When the compute reads an uncached stored field on one of them, fetch() raises an AccessError. The AccessError is caught and goes to the single-record fallback in Field.__get__, so the compute runs once per record. When the compute makes queries (for instance _compute_is_reminder_on on event tracks for public users), this costs one query per record instead of one per batch. Fix this issue by introducing an intermediate step, where we restrict the batch to existing and accessible records. When that one fails, we eventually fall back on the single record case. Related: odoo/enterprise#134688