Commit c4584f8
committed
[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))
```
[domain]: https://github.com/odoo/odoo/blob/2f0f8e5e00685129b5bbe954117bc9f80a568e88/odoo/orm/models.py#L5365-L5371
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.
upg- 45787731 parent be32312 commit c4584f8
1 file changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
559 | 586 | | |
560 | 587 | | |
561 | 588 | | |
| |||
812 | 839 | | |
813 | 840 | | |
814 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
815 | 847 | | |
816 | 848 | | |
817 | 849 | | |
| |||
0 commit comments