From ad993e673dd7c227bc30c168a379e80eb804d886 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Thu, 16 Nov 2023 14:12:46 +0100 Subject: [PATCH] [FIX] base: avoid no autoinstall propagation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A custom script is modifying the output of load_information_from_description_file to disable the auto-install of modules during local testing. It was naively adapted for v16.0 by replacing the corresponding methods. Since a lru cache was added (nice optimization in most cases) this is an issue because running lint test afterward will get the cached value with an incorrect autoinstall value. It makes sens to avoid reading the file on the filesystem each time, but making a deepcopy looks like an acceptable safeguard to avoid hard to debug behaviors. closes odoo/odoo#143628 X-original-commit: ad10ff4410ccf7c38f6154480484495bb57c53ff Signed-off-by: Julien Castiaux (juc) Signed-off-by: Xavier Dollé (xdo) --- addons/website/tests/test_views.py | 8 ++++---- odoo/addons/base/tests/test_module.py | 9 +++++++++ odoo/modules/module.py | 6 +++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/addons/website/tests/test_views.py b/addons/website/tests/test_views.py index 393001f1b3a..bb7f08d2a2b 100644 --- a/addons/website/tests/test_views.py +++ b/addons/website/tests/test_views.py @@ -2,13 +2,14 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from hashlib import sha256 +import copy import unittest from unittest.mock import patch from itertools import zip_longest from lxml import etree as ET, html from lxml.html import builder as h -from odoo.modules.module import _DEFAULT_MANIFEST, get_manifest +from odoo.modules.module import _DEFAULT_MANIFEST from odoo.tests import common, HttpCase, tagged @@ -1510,10 +1511,9 @@ class TestThemeViews(common.TransactionCase): main_view.with_context(website_id=website_1.id).arch = 'specific' # 2. Simulate a theme install with a child view of `main_view` + patcher = patch('odoo.modules.module._get_manifest_cached', return_value=copy.deepcopy(_DEFAULT_MANIFEST)) + self.startPatcher(patcher) test_theme_module = self.env['ir.module.module'].create({'name': 'test_theme'}) - # Themes are required to have a valid manifest, including a `new_page_templates` property. - # This theme is created in python and therefore has no manifest. - get_manifest('test_theme').update(_DEFAULT_MANIFEST) self.env['ir.model.data'].create({ 'module': 'base', 'name': 'module_test_theme_module', diff --git a/odoo/addons/base/tests/test_module.py b/odoo/addons/base/tests/test_module.py index 1d2009db54c..b37c72e9485 100644 --- a/odoo/addons/base/tests/test_module.py +++ b/odoo/addons/base/tests/test_module.py @@ -7,6 +7,7 @@ from unittest.mock import patch import odoo.addons from odoo.modules.module import load_manifest +from odoo.modules.module import get_manifest from odoo.release import major_version from odoo.tests.common import BaseCase @@ -71,6 +72,14 @@ class TestModuleManifest(BaseCase): 'website': '', }) + def test_change_manifest(self): + module_name = 'base' + new_manifest = get_manifest(module_name) + orig_auto_install = new_manifest['auto_install'] + new_manifest['auto_install'] = not orig_auto_install + self.assertNotEqual(new_manifest, get_manifest(module_name)) + self.assertEqual(orig_auto_install, get_manifest(module_name)['auto_install']) + def test_missing_manifest(self): with self.assertLogs('odoo.modules.module', 'DEBUG') as capture: manifest = load_manifest(self.module_name) diff --git a/odoo/modules/module.py b/odoo/modules/module.py index a12fd5e9a41..c93a630c0d4 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -312,6 +312,7 @@ def load_manifest(module, mod_path=None): return {} manifest = copy.deepcopy(_DEFAULT_MANIFEST) + manifest['icon'] = get_module_icon(module) with tools.file_open(manifest_file, mode='r') as f: @@ -352,7 +353,6 @@ def load_manifest(module, mod_path=None): return manifest -@functools.lru_cache(maxsize=None) def get_manifest(module, mod_path=None): """ Get the module manifest. @@ -365,6 +365,10 @@ def get_manifest(module, mod_path=None): when the manifest was not found. :rtype: dict """ + return copy.deepcopy(_get_manifest_cached(module, mod_path)) + +@functools.lru_cache(maxsize=None) +def _get_manifest_cached(module, mod_path=None): return load_manifest(module, mod_path) def load_information_from_description_file(module, mod_path=None):