Skip to content

[fork-CI] [19.0][IMP] base_search_fuzzy: translatable trigram support (#3429 + 19.0 adaptations)#13

Closed
dnplkndll wants to merge 53 commits into
19.0from
19.0-mig-bsf-trgm-translatable
Closed

[fork-CI] [19.0][IMP] base_search_fuzzy: translatable trigram support (#3429 + 19.0 adaptations)#13
dnplkndll wants to merge 53 commits into
19.0from
19.0-mig-bsf-trgm-translatable

Conversation

@dnplkndll

Copy link
Copy Markdown

Fork-CI verification branch for pedrobaeza's ask on OCA/server-tools#3620: include #3429 (translatable-fields trigram support) in the 19.0 migration.

Sits on the live PR branch (19.0-mig-base_search_fuzzy, unchanged below) plus:

Verified on a 19.0 slot: 8/8 tests green both --without-demo=all (OCA CI parity) and with demo, incl. a new end-to-end translatable search (expression-index creation + real % query execution).

Christoph Giesel and others added 30 commits May 20, 2026 19:02
…s, added translations, added access permissions, moved the monkey patching to method _register_hook of ir.model and fixed _auto_init, added README, cleaned up some aprts
…references to odoo * Bump version * Upgrade api usages
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-12.0/server-tools-12.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_search_fuzzy/
Currently translated at 94.7% (18 of 19 strings)

Translation: server-tools-12.0/server-tools-12.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_search_fuzzy/pt/
Currently translated at 100.0% (19 of 19 strings)

Translation: server-tools-12.0/server-tools-12.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_search_fuzzy/pt_BR/
Currently translated at 100.0% (19 of 19 strings)

Translation: server-tools-12.0/server-tools-12.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-base_search_fuzzy/zh_CN/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-13.0/server-tools-13.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-13-0/server-tools-13-0-base_search_fuzzy/
- [Server-wide patching should be done in `post_load` hook][1], and there's where it's done now.
- Remove similarity order, as it had no use in the wild and was buggy.
- Refactor monkey patch to remove some nonsense.
- Move tests to at_install mode, now that the patch is installed correctly.

@Tecnativa TT31444
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-14.0/server-tools-14.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-base_search_fuzzy/
Currently translated at 100.0% (18 of 18 strings)

Translation: server-tools-14.0/server-tools-14.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-base_search_fuzzy/pt_BR/
[ADD] Roadmap: Module no longer needed from v16
Currently translated at 100.0% (18 of 18 strings)

Translation: server-tools-15.0/server-tools-15.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-base_search_fuzzy/es_AR/
Nikul-OSI and others added 23 commits May 20, 2026 19:02
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/
Currently translated at 47.0% (8 of 17 strings)

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/it/
Currently translated at 88.2% (15 of 17 strings)

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/sl/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/
Currently translated at 100.0% (18 of 18 strings)

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/es/
Currently translated at 100.0% (18 of 18 strings)

Translation: server-tools-16.0/server-tools-16.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-base_search_fuzzy/it/
Currently translated at 100.0% (18 of 18 strings)

Translation: server-tools-18.0/server-tools-18.0-base_search_fuzzy
Translate-URL: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_search_fuzzy/nl/
Re-implements the PostgreSQL trigram similarity operator ``%`` using
Odoo 19's ``@operator_optimization`` decorator + ``Domain.custom``.

The 18.0 ``post_load`` hook that mutated
``odoo.osv.expression.TERM_OPERATORS`` and ``SQL_OPERATORS`` no longer
works in 19.0:

- ``SQL_OPERATORS`` moved from ``odoo.osv.expression`` to
  ``odoo.orm.utils`` (no re-export).
- ``TERM_OPERATORS`` is now a rebound copy of
  ``odoo.orm.domains.CONDITION_OPERATORS``; the new ``Domain``
  validator keys off ``CONDITION_OPERATORS`` directly, so mutating
  ``expression.TERM_OPERATORS`` no longer registers the operator.
- The new generic ``Field._condition_to_sql`` does not consult
  ``SQL_OPERATORS`` for unknown operators; an unknown operator like
  ``%`` raises ``NotImplementedError``.

The replacement registers the operator at import time via
``@operator_optimization(['%'])`` and emits the trigram-similarity
predicate through ``Domain.custom(to_sql=...)`` — the supported path
used in core by ``auth_totp``, ``analytic_mixin`` and
``account_tax``. ``post_load`` is dropped from the manifest, and
``hooks.py`` is removed.

Tests assert ``%`` is in ``CONDITION_OPERATORS`` and verify the
emitted SQL contains the field reference + escaped ``%%`` template;
the end-to-end ``pg_trgm`` test is unchanged.
The `%` similarity predicate now renders as `(<field>) %% <value>`.

A translatable field renders in SQL as the bare JSON accessor
`name->>'en_US'` (core's BaseString.to_sql does not wrap the
single-language case). `%` binds tighter than `->>`, so the previous
`name->>'en_US' %% 'foo'` parsed as `name->>('en_US' %% 'foo')` and
failed with "operator does not exist: jsonb ->> boolean". The 18.0
module relies on the still-unmerged core PR odoo/odoo#232993 to add
this wrapping; on 19.0 the operator is emitted by this module's own
Domain.custom, so we parenthesize here instead and carry no core
dependency.

The parentheses also make the predicate match the parenthesized
expression index that trgm_index builds for translatable columns
(`(name->>'en_US')` / `COALESCE(name->>'lang', name->>'en_US')`),
introduced by the translatable-fields support picked from OCA#3429.

Exact-SQL test assertions updated to the parenthesized form.
CREATE INDEX folds the unquoted identifier to lowercase, but
get_not_used_index compares the generated name literally against
pg_indexes, so the mixed-case lang component (`name_en_US_gin_idx`)
never matches the stored `name_en_us_gin_idx` and collision detection
silently fails for every translatable index. Build the name lowercase.

Adds an end-to-end test: trgm.index creation on a translatable field
(res.partner.category.name) verified against pg_indexes, then an actual
`%` search in lang context.
The test hardcoded name_gin_idx, which the module's own demo data
already creates on res_partner, so the test errored on any demo-loaded
database (OCA CI is demo-less and never hit it). Use a name the demo
data cannot take.
@dnplkndll dnplkndll closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.