Do not insert local paths before standard library paths#68756
Open
marmarek wants to merge 4 commits intosaltstack:3006.xfrom
Open
Do not insert local paths before standard library paths#68756marmarek wants to merge 4 commits intosaltstack:3006.xfrom
marmarek wants to merge 4 commits intosaltstack:3006.xfrom
Conversation
Contributor
Author
|
The failure I get is: Is it related to my change? I think it isn't given I got it also in https://github.com/saltstack/salt/actions/runs/22261566839, which doesn't include this change. |
twangboy
requested changes
Feb 24, 2026
Contributor
twangboy
left a comment
There was a problem hiding this comment.
Please create this against the 3006.x branch as the bug also exists there.
bdddbea to
247e43f
Compare
Contributor
Author
Done. |
Inserting local paths like `salt/utils` before standard library makes
many modules in utils conflict with standard library. This is especially
relevant for salt-ssh. For example salt.utils.configparser - it tries to
import configparser from stdlib, but due to salt/utils path being
prepended to sys.path, it imports itself:
[ERROR ] Failed to import fileserver gitfs, this is due most likely to a syntax error:
Traceback (most recent call last):
File "/var/tmp/.root_dd8a91_salt/pyall/salt/loader/lazy.py", line 902, in _load_module
self.run(spec.loader.exec_module, mod)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/tmp/.root_dd8a91_salt/pyall/salt/loader/lazy.py", line 1365, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/tmp/.root_dd8a91_salt/pyall/salt/loader/lazy.py", line 1380, in _run_as
ret = _func_or_method(*args, **kwargs)
File "<frozen importlib._bootstrap_external>", line 1023, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/var/tmp/.root_dd8a91_salt/pyall/salt/fileserver/gitfs.py", line 52, in <module>
import salt.utils.gitfs
File "/var/tmp/.root_dd8a91_salt/pyall/salt/utils/gitfs.py", line 31, in <module>
import salt.utils.configparser
File "/var/tmp/.root_dd8a91_salt/pyall/salt/utils/configparser.py", line 7, in <module>
from configparser import * # pylint: disable=no-name-in-module,wildcard-import,unused-wildcard-import
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/tmp/.root_dd8a91_salt/running_data/var/cache/salt/minion/extmods/utils/configparser.py", line 12, in <module>
class GitConfigParser(RawConfigParser):
^^^^^^^^^^^^^^^
NameError: name 'RawConfigParser' is not defined
On the other hand, places that try to use such duplicated modules from
utils, import them via full name (as seen above: `import salt.utils.configparser`).
Change the insert_system_path() function to not insert paths before
standard library.
Fixes saltstack#68755
Temporarily for checkig if test works. This reverts commit b13c203.
Check if it works correctly, especially if it can be imported.
20f5ae2 to
acac2e7
Compare
The saltstack#68755 issue is caused by wrong adjustments of sys.path. But due to another bug, such adjustment is later undone when __utils__ is used. If it gets undone before pkg is (attempted) imported, the test succeeds even when it should fail. Limit what modules are loaded, to make the test more effective.
acac2e7 to
ae49752
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Inserting local paths like
salt/utilsbefore standard library makes many modules in utils conflict with standard library. This is especially relevant for salt-ssh. For example salt.utils.configparser - it tries to import configparser from stdlib, but due to salt/utils path being prepended to sys.path, it imports itself:On the other hand, places that try to use such duplicated modules from utils, import them via full name (as seen above:
import salt.utils.configparser).Change the insert_system_path() function to not insert paths before standard library.
What issues does this PR fix or reference?
Fixes #68755
Previous Behavior
Several state modules (including
pkg.installedon RedHat-based distro) are unavailable via salt-sshNew Behavior
No import conflict,
pkg.installedworks.Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes