Skip to content

[IMP] openupgrade: strip_view_arch_attrs() helper for RNG-removed attrs#2

Draft
dnplkndll wants to merge 4 commits into
masterfrom
19.0-add-strip-view-arch-attrs
Draft

[IMP] openupgrade: strip_view_arch_attrs() helper for RNG-removed attrs#2
dnplkndll wants to merge 4 commits into
masterfrom
19.0-add-strip-view-arch-attrs

Conversation

@dnplkndll
Copy link
Copy Markdown

Common shape across major Odoo migrations: a RelaxNG schema tightens between versions, attributes valid in N become invalid in N+1, and stored arch_db blobs that still carry them fail view validation when the module is upgraded — leaving the view unrenderable and breaking downstream xml_id lookups.

This helper does the SQL-side pre-migration scrub, scoped by view type, with (element_regex, attr_regex) pattern pairs. Multi-lang jsonb arch_db (17.0+) handled via jsonb_each + jsonb_object_agg.

Signature

strip_view_arch_attrs(cr, view_type, attr_patterns, like_hints=None)
  • view_type: 'search', 'form', etc. Strict type-scoping is intentional — RNG removals are type-specific. e.g. <list expand=...> remained valid in 19.0 even though <group expand=...> was removed; broader stripping would brick the list views.
  • attr_patterns: iterable of (element_regex, attr_regex) POSIX regex pairs. Strips <{element_regex}[^>]*?\s+{attr_regex} occurrences, preserving the rest of the element tag.
  • like_hints: optional substring filter to skip views that clearly carry none of the patterns (cheap pre-filter).

First consumer

OpenUpgrade base/19.0.1.3/pre-migration.py strips <group expand=...>, <field expand=...> (searchpanel), and <group string="Group By"> from <search> views, which the 19.0 RNG schema rejects:

openupgrade.strip_view_arch_attrs(env.cr, "search", [
    ("(?:group|field)", 'expand="[^"]*"'),
    ("group", 'string="Group By"'),
], like_hints=["expand=", 'string="Group By"'])

Validated on a Tier-1 600-module Odoo seed: 181 affected views → 0 post-migration, sub-second wall-clock.

Notes

  • Pre-17.0 arch_db is text not jsonb; helper raises rather than silently using the wrong code path.
  • Each pattern runs as a separate nested regexp_replace; not combined into a single alternation for clarity.
  • Backreference \1 preserves any other attrs on the same element tag.

dnplkndll and others added 4 commits May 21, 2026 08:26
…ng_card UPDATE

The card_campaign cross-reference UPDATE inside merge_models() (active when
marketing_card is installed) had two bugs:

1. Used `{old_model}` / `{new_model}` as sql.SQL().format() placeholders but
   passed them via the psycopg2 params dict — raising
   `KeyError: 'old_model'` from psycopg2/sql.py at runtime.
2. Double `AND` in WHERE clause:
   `AND mt.{ref_field} = c.res_id AND AND c.campaign_id = cc.id`

Both fixed: switch to `%(old_model)s` / `%(new_model)s` (matching the params
dict) and remove the redundant AND.

Triggered in practice by any model-merge migration when marketing_card is
installed (e.g., OCA/OpenUpgrade hr_recruitment hr.candidate -> hr.applicant
merge on 18.0 -> 19.0).
[FIX] merge_models: psycopg2 param style + double-AND typo (marketing_card UPDATE)
Common shape across major Odoo migrations: a RelaxNG schema tightens
between versions, attributes valid in N become invalid in N+1, and
stored arch_db blobs that still carry them fail view validation when
the module is upgraded — leaving the view unrenderable and breaking
downstream xml_id lookups.

This helper does the SQL-side pre-migration scrub: scoped by view type,
takes a list of (element_regex, attr_regex) patterns, and rewrites
arch_db with the matches stripped. Multi-lang jsonb arch_db (17.0+)
handled via jsonb_each + jsonb_object_agg.

First consumer: openupgrade_scripts/scripts/base/19.0.1.3 strips
<group expand=...>, <field expand=...>, and <group string="Group By">
from <search> views, which the 19.0 RNG schema rejects.
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.

2 participants