From 4db506c49f8c4e8dcf73ec9bfdba40010b626173 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 10 Sep 2023 12:28:48 +0200 Subject: [PATCH] PICARD-2751: Avoid plugins with relative imports executing plugin body twice --- picard/pluginmanager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/picard/pluginmanager.py b/picard/pluginmanager.py index 6fdf00e8e..da33d9ccf 100644 --- a/picard/pluginmanager.py +++ b/picard/pluginmanager.py @@ -353,6 +353,12 @@ class PluginManager(QtCore.QObject): plugin_module = zip_importer.load_module(full_module_name) else: plugin_module = importlib.util.module_from_spec(spec) + # This is kind of a hack. The module will be in sys.modules + # after exec_module has run. But if inside of the loaded plugin + # there are relative imports it would load the same plugin + # module twice. This executes the plugins code twice and leads + # to potential side effects. + sys.modules[full_module_name] = plugin_module spec.loader.exec_module(plugin_module) plugin = PluginWrapper(plugin_module, plugindir,