From ae5c3872298fb1d929f81c39bb41d8977ee768ba Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Fri, 7 Nov 2025 07:41:05 +0100 Subject: [PATCH] [FIX] don't set install_filename when loading views from openupgrade_scripts fixes #5437 Changes compared to 527770f: - use a view from a 17.0.x noupdate_changes.xml file instead of a 18.0.x one in unit test - disable pylint warning due to voluntary context override --- .../odoo/addons/base/models/ir_ui_view.py | 19 +++++++++++++++++++ .../scripts/portal/tests/test_arch_fs.py | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 openupgrade_scripts/scripts/portal/tests/test_arch_fs.py diff --git a/openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_ui_view.py b/openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_ui_view.py index 0cec05eab184..fa959248a760 100644 --- a/openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_ui_view.py +++ b/openupgrade_framework/odoo_patch/odoo/addons/base/models/ir_ui_view.py @@ -5,6 +5,7 @@ from odoo import api from odoo.exceptions import ValidationError +from odoo.modules.module import get_resource_from_path from odoo.tools import mute_logger from odoo.addons.base.models.ir_ui_view import NameManager, View @@ -85,6 +86,22 @@ def _check_field_paths(self, node, field_paths, model_name, use): pass +def _inverse_arch(self): + """ + Remove install_filename from context if it's from openupgrade_scripts. + Without this, arch_fs will point to openupgrade_scripts' file which most likely + won't exist when the migrated database is deployed, which breaks resetting views + """ + if "install_filename" in self._context: + path_info = get_resource_from_path(self._context["install_filename"]) + if path_info[0] == "openupgrade_scripts": + # Needs to override the context to remove the install_filename + self = self.with_context( # pylint: disable=context-overridden + {k: v for k, v in self._context.items() if k != "install_filename"} + ) + return _inverse_arch._original_method(self) + + _check_xml._original_method = View._check_xml View._check_xml = _check_xml check._original_method = NameManager.check @@ -93,3 +110,5 @@ def _check_field_paths(self, node, field_paths, model_name, use): View._raise_view_error = _raise_view_error _check_field_paths._original_method = View._check_field_paths View._check_field_paths = _check_field_paths +_inverse_arch._original_method = View._inverse_arch +View._inverse_arch = _inverse_arch diff --git a/openupgrade_scripts/scripts/portal/tests/test_arch_fs.py b/openupgrade_scripts/scripts/portal/tests/test_arch_fs.py new file mode 100644 index 000000000000..3d0c8f485d5e --- /dev/null +++ b/openupgrade_scripts/scripts/portal/tests/test_arch_fs.py @@ -0,0 +1,16 @@ +from odoo.tests import TransactionCase + +from odoo.addons.openupgrade_framework import openupgrade_test + + +@openupgrade_test +class TestArchFs(TransactionCase): + def test_arch_fs(self): + """ + Test that we didn't overwrite arch_fs with the path to the + noupdate changes file + """ + self.assertNotIn( + "openupgrade_scripts", + self.env.ref("portal.portal_share_template").arch_fs, + )