odoo/upgrade-util#485
Created by Sanchit Gupta (sagu)
Blocked
- Merge method
- Review
-
CI
- ci/runbot: Test upgrades between stable versions
- ci/upgrade_enterprise: Test upgrades for enterprise master
- label
- odoo-dev:master-fix-no-sql-sagu
- head
- 5376110c16f9e32dd0d3292bbfd92abae950cef4
| odoo/upgrade-util | |
|---|---|
| master | #485 missing r+ |
[FIX] util/orm: Fix non store field issue
Since 18.3, domain resolution goes strictly through _search
domain.optimize_full(model)
if not domain.is_true():
query.add_where(domain._to_sql(self, self._table, query))
optimize_full() leaves a leaf untouched when the field has no search= defined, so _to_sql() calls field.to_sql() directly. For non-stored fields this now raises:
File "/home/odoo/src/odoo/19.0/odoo/orm/models.py", line 5256, in _order_to_sql
term = self._order_field_to_sql(alias, field_name, sql_direction, sql_nulls, query)
File "/home/odoo/src/odoo/19.0/odoo/orm/models.py", line 5315, in _order_field_to_sql
sql_field = self._field_to_sql(alias, field_name, query)
File "/home/odoo/src/odoo/19.0/odoo/orm/models.py", line 2930, in _field_to_sql
sql = field.to_sql(self, alias)
File "/home/odoo/src/odoo/19.0/odoo/orm/fields_textual.py", line 395, in to_sql
sql_field = super().to_sql(model, alias)
File "/home/odoo/src/odoo/19.0/odoo/orm/fields.py", line 1216, in to_sql
raise ValueError(f"Cannot convert {self} to SQL because it is not stored")
ValueError: Cannot convert photovoltaics.installer.name to SQL because it is not stored
Previously (pre-18.3), such leaves were treated as always-true instead of raising:
https://github.com/odoo/odoo/blob/d9c06a66356dd9d5a50821b8cde6194967353c18/odoo/osv/expression.py#L1180-L1187
Since we don't always know if a custom/third-party field is stored or searchable, assign a dummy search= returning an always-true leaf (e.g. [(1, '=', 1)]). This makes optimize_full() resolve the domain to is_true() before _to_sql() runs, restoring the old behavior and avoiding the ValueError.