From 889e0cecfceeb7849ff03e2218385b3ce7240f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 27 Feb 2026 23:26:05 +0100 Subject: [PATCH 1/3] Add test for pkg.installed state Check if it works correctly, especially if it can be imported. --- tests/pytests/integration/ssh/state/test_state.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/pytests/integration/ssh/state/test_state.py b/tests/pytests/integration/ssh/state/test_state.py index f9fd126bb67c..5fbbc15426e0 100644 --- a/tests/pytests/integration/ssh/state/test_state.py +++ b/tests/pytests/integration/ssh/state/test_state.py @@ -113,3 +113,10 @@ def test_state_test(salt_ssh_cli, state_tree): ret.data["test_|-Ok with def_|-Ok with def_|-succeed_with_changes"]["result"] is None ) + + +def test_state_pkg(salt_ssh_cli): + ret = salt_ssh_cli.run("state.single", "pkg.installed", "coreutils", "test=True") + assert ret.returncode == 0 + assert ret.data + assert ret.data["pkg_|-coreutils_|-coreutils_|-installed"]["result"] is not False From 3d3a9f2c9e1e9f86608adf1da7c114d9ff190a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 2 Mar 2026 04:05:05 +0100 Subject: [PATCH 2/3] Avoid sys.path modification as a side effect of LazyLoader LazyLoader._load_module() appends a dir of imported module (fpath_dirname) to sys.path and then undoes that change by sys.path.remove(). But if that directory was in sys.path already, the remove call will remove an earlier item than the appended one - effectively changing the items order in sys.path. Fix this by avoiding adding and removing fpath_dirname if it was in sys.path already. Ironically, this side effect sometimes (depending on module discovery order) cancels out with bug #68755 (the wrongly removed path is the one that was wrongly inserted in the first place). While contributed to it being unnoticed for quite some time, and made writting a test of the fix harder. --- salt/loader/lazy.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/salt/loader/lazy.py b/salt/loader/lazy.py index 193a6f9a579b..d1d7fc7cad1e 100644 --- a/salt/loader/lazy.py +++ b/salt/loader/lazy.py @@ -778,9 +778,12 @@ def _load_module(self, name): self.loaded_files.add(name) fpath_dirname = os.path.dirname(fpath) + fpath_appended = False try: self.__populate_sys_path() - sys.path.append(fpath_dirname) + if fpath_dirname not in sys.path: + sys.path.append(fpath_dirname) + fpath_appended = True if suffix == ".pyx": mod = pyximport.load_module(name, fpath, tempfile.gettempdir()) elif suffix == ".o": @@ -917,7 +920,8 @@ def _load_module(self, name): self.missing_modules[name] = error return False finally: - sys.path.remove(fpath_dirname) + if fpath_appended: + sys.path.remove(fpath_dirname) self.__clean_sys_path() loader_context = salt.loader.context.LoaderContext() From 3335f55b4c3004406770ca95539843b4146dd05c Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Thu, 18 Jun 2026 15:34:53 -0700 Subject: [PATCH 3/3] Add changelog/68755.fixed.md --- changelog/68755.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/68755.fixed.md diff --git a/changelog/68755.fixed.md b/changelog/68755.fixed.md new file mode 100644 index 000000000000..b6f106c582c0 --- /dev/null +++ b/changelog/68755.fixed.md @@ -0,0 +1 @@ +Don't insert local paths before standard library paths in LazyLoader, preventing sys.path reordering when loader modules are already importable.