From 1069763b3af126211cf8a0bbbded0ea755fb09a4 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Mon, 11 Dec 2023 18:37:26 +0100 Subject: [PATCH] [FIX] core: importlib find_module is deprecated As find_module has been deprecated since python 3.4: https://github.com/python/cpython/blob/05c28b08f6e2fc8782472b026c98a3fdd61a2ba9/Lib/importlib/_bootstrap.py#L1347 and warnings added in python 3.10: https://github.com/python/cpython/blob/f91dfdf5ff9f68a4b012e1b70ab9997c6dc1542d/Lib/importlib/_bootstrap.py#L764 to respect the PEP-451 specification : https://peps.python.org/pep-0451/ So, override the find_spec() method to display depreaction warnings if applicable. X-original-commit: 000ce83492d67febc8b45b902500d57304455d04 --- This commit should have been merged by odoo/odoo#128924, but has been wrongly ignored. This oversight has been detected due to a fix inside the `find_spec` method (odoo/odoo#145800) that couldn't be forward-ported. This commit is therefore the combinaison of those two patches and the removal of the depreacted `find_module` method. closes odoo/odoo#146205 X-original-commit: df63a8aede024f7d4423f80f270a4aa662150e3e Signed-off-by: Christophe Simonis (chs) Co-authored-by: Enric Tobella Co-authored-by: Christophe Simonis --- odoo/modules/module.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/odoo/modules/module.py b/odoo/modules/module.py index c93a630c0d4..7281207531c 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -68,13 +68,13 @@ _logger = logging.getLogger(__name__) class UpgradeHook(object): """Makes the legacy `migrations` package being `odoo.upgrade`""" - def find_module(self, name, path=None): - if re.match(r"^odoo\.addons\.base\.maintenance\.migrations\b", name): + def find_spec(self, fullname, path=None, target=None): + if re.match(r"^odoo\.addons\.base\.maintenance\.migrations\b", fullname): # We can't trigger a DeprecationWarning in this case. # In order to be cross-versions, the multi-versions upgrade scripts (0.0.0 scripts), # the tests, and the common files (utility functions) still needs to import from the # legacy name. - return self + return importlib.util.spec_from_loader(fullname, self) def load_module(self, name): assert name not in sys.modules