diff --git a/openupgrade_scripts/scripts/base/19.0.1.3/pre-migration.py b/openupgrade_scripts/scripts/base/19.0.1.3/pre-migration.py index 39b145615b4b..7a86655a677d 100644 --- a/openupgrade_scripts/scripts/base/19.0.1.3/pre-migration.py +++ b/openupgrade_scripts/scripts/base/19.0.1.3/pre-migration.py @@ -176,3 +176,41 @@ def migrate(env, version): openupgrade.rename_xmlids(env.cr, _renamed_xmlids) openupgrade.rename_xmlids(env.cr, _merged_xmlids, allow_merge=True) openupgrade.rename_fields(env, _renamed_fields) + _strip_removed_search_view_attrs(env) + + +def _strip_removed_search_view_attrs(env): + """Strip 19.0 RNG-removed attrs (`expand=` on /, + `string="Group By"` on ) from stored search-view arch_db. + """ + openupgrade.logged_query( + env.cr, + r""" + UPDATE ir_ui_view v + SET arch_db = sub.new_arch + FROM ( + SELECT id, + jsonb_object_agg( + lang, + to_jsonb( + regexp_replace( + regexp_replace(content, + '(<(?:group|field)[^>]*?)\s+expand="[^"]*"', + '\1', 'g'), + '(]*?)\s+string="Group By"', + '\1', 'g' + ) + ) + ) AS new_arch + FROM ( + SELECT v2.id, je.key AS lang, je.value #>> '{}' AS content + FROM ir_ui_view v2, jsonb_each(v2.arch_db) je + WHERE v2.type='search' + AND (v2.arch_db::text LIKE '%%expand=%%' + OR v2.arch_db::text LIKE '%%string="Group By"%%') + ) flat + GROUP BY id + ) sub + WHERE v.id = sub.id + """, + ) diff --git a/openupgrade_scripts/scripts/base/tests/data_base_migration.py b/openupgrade_scripts/scripts/base/tests/data_base_migration.py index 472065b36553..6c5278073116 100644 --- a/openupgrade_scripts/scripts/base/tests/data_base_migration.py +++ b/openupgrade_scripts/scripts/base/tests/data_base_migration.py @@ -41,4 +41,42 @@ ], } ) + +# Search-view fixtures for the 19.0 RNG attribute strip helper. +# `expand=` on / and `string="Group By"` on +# were valid in 18.0 but rejected by 19.0's stricter RelaxNG schema. +env["ir.ui.view"].create( + { + "name": "test search group_expand", + "model": "res.partner", + "type": "search", + "arch": """ + + + + + + + """, + } +) +env["ir.ui.view"].create( + { + "name": "test search field_expand", + "model": "res.partner", + "type": "search", + "arch": """ + + + + + + + """, + } +) env.cr.commit() diff --git a/openupgrade_scripts/scripts/base/tests/test_base_migration.py b/openupgrade_scripts/scripts/base/tests/test_base_migration.py index 525218394f51..80a67cc9909d 100644 --- a/openupgrade_scripts/scripts/base/tests/test_base_migration.py +++ b/openupgrade_scripts/scripts/base/tests/test_base_migration.py @@ -24,3 +24,41 @@ def test_server_action_child_ids(self): action2.child_ids.mapped("name"), ("child action 1", "child action 2", "child action 3"), ) + + def test_strip_removed_search_view_attrs(self): + """19.0 RNG-removed attrs (`expand=` on /, + `string="Group By"` on ) are stripped from arch_db + on search views; legitimate attrs are preserved. + """ + view_group = self.env["ir.ui.view"].search( + [("name", "=", "test search group_expand")] + ) + self.assertTrue(view_group) + arch_group = view_group.arch_db + self.assertNotIn( + 'expand="0"', + arch_group, + "expand= should be stripped from in search arch", + ) + self.assertNotIn( + 'string="Group By"', + arch_group, + 'string="Group By" should be stripped from ', + ) + # Legit attrs preserved + self.assertIn('name="country"', arch_group) + self.assertIn('string="Country"', arch_group) + + view_field = self.env["ir.ui.view"].search( + [("name", "=", "test search field_expand")] + ) + self.assertTrue(view_field) + arch_field = view_field.arch_db + self.assertNotIn( + 'expand="1"', + arch_field, + "expand= should be stripped from in searchpanel", + ) + # Legit attrs preserved + self.assertIn('select="multi"', arch_field) + self.assertIn('name="country_id"', arch_field)