[fork-CI] [19.0][IMP] base_search_fuzzy: translatable trigram support (#3429 + 19.0 adaptations)#13
Closed
dnplkndll wants to merge 53 commits into
Closed
[fork-CI] [19.0][IMP] base_search_fuzzy: translatable trigram support (#3429 + 19.0 adaptations)#13dnplkndll wants to merge 53 commits into
dnplkndll wants to merge 53 commits into
Conversation
…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/
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.
(cherry picked from commit e8c0b1a)
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:[IMP]yvaucher's [IMP] base_search_fuzzy - add support of translatable fields OCA/server-tools#3429 pick (-x, authorship intact)[IMP]parenthesize the%operand — on 19.0 the operator is emitted by this module's ownDomain.custom; the bare JSON accessorname->>'en_US' % 'foo'hard-errors (operator does not exist: jsonb ->> boolean,%binds tighter than->>). 18.0 relies on still-unmerged [18.0][IMP] core: JSON operator compatibility with pg_trgm % operator odoo/odoo#232993; 19.0 is self-contained.[FIX]lowercase the translatable index name — Postgres folds the unquotedname_en_US_gin_idxidentifier, soget_not_used_index's literalpg_indexeslookup never matched (latent in the 18.0 merge too)[FIX]demo-proof the hardcoded-index-name collision testVerified 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).