Do not insert local paths before standard library paths#68756
Do not insert local paths before standard library paths#68756marmarek wants to merge 4 commits intosaltstack:3006.xfrom
Conversation
|
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
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
Done. |
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 saltstack#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.
ae49752 to
3acb784
Compare
|
@twangboy do you have some idea what is different in CI that the bug doesn't happen here? In the process of testing the test, I found another |
|
I don't, maybe @dwoz could take a look. You're saying that the passing tests below should not be passing, correct? |
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