Repository navigation
Fix linux_shadow and solaris_shadow spwd usage on Python 3.13+ (#64264) - #69651
Merged
Merged
Conversation
Module deprecated and no longer shipped with Python 3.13. Co-authored-by: Toyam Cox <[email protected]> Co-authored-by: Georg Pfuetzenreuter <[email protected]> Signed-off-by: Georg Pfuetzenreuter <[email protected]>
The stdlib ``spwd`` module was deprecated in Python 3.11 and removed in Python 3.13. ``salt.modules.solaris_shadow`` still tried to import it and to reference ``spwd.getspnam``/``spwd.struct_spwd`` on the primary Solaris code path, mirroring the earlier ``linux_shadow`` breakage tracked in this issue. Replace the ``spwd`` primary path with a local ``_getspnam`` that reads ``/etc/shadow`` directly and returns a ``struct_spwd``-compatible namedtuple, matching the pattern already used in ``linux_shadow`` (see commit a5cd311). The SmartOS-style ``pwd`` + ``passwd -s`` fallback is preserved for the case where ``/etc/shadow`` is not readable. Update the ``linux_shadow`` and ``solaris_shadow`` unit tests to patch the new ``_getspnam`` helper instead of ``spwd.getspnam`` so the suites run on Python 3.13+. Fixes saltstack#64264
kzndzhiro
reviewed
Jul 5, 2026
twangboy
previously approved these changes
Jul 6, 2026
- Replace `except (KeyError, FileNotFoundError)` with `except (KeyError, OSError)` in both linux_shadow.py and solaris_shadow.py so that PermissionError (and any other OS-level error reading /etc/shadow) falls back gracefully rather than propagating to the caller.
kzndzhiro
approved these changes
Jul 7, 2026
This branch was previously deployed
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?
Removes the last uses of the removed-in-Python-3.13
spwdstdlib modulefrom Salt's shadow modules, so
shadow.infono longer crashes withNameError: name 'spwd' is not definedon Python 3.13+.Two-part change against
3006.x:a5cd3113f2d"Remove uses of spwd" (originallyauthored by Toyam Cox / Georg Pfuetzenreuter, referencing [BUG] Salt relies on spwd module, deprecated in 3.11 and removed in 3.13 #67119)
which fixes
salt/modules/linux_shadow.py. That commit currentlylives on
3007.x/3008.x/masterbut has not yet shipped inany 3007 release tag (latest tag is
v3007.14), and it has neverbeen on
3006.x.salt/modules/solaris_shadow.py(stillimport spwdon every branch, includingmaster) plus rewrites ofthe affected unit tests so they run on Python 3.13+ (they previously
importorskip('spwd'), which silently disabled all coverage on thenew interpreters).
Merge-forward will carry the solaris_shadow removal from 3006.x up
through 3007.x, 3008.x, and master; the linux_shadow cherry-pick is a
no-op on 3007.x+ because the fix is already there.
What issues does this PR fix or reference?
Fixes #64264
Previous Behavior
On Python 3.13,
salt.modules.linux_shadow.inforaised at first use:salt.modules.solaris_shadowstill importedspwdat module load(deprecation warning on 3.11/3.12,
ImportErrorswallowed on 3.13+),and its
HAS_SPWD-guarded primary Solaris code path was silently deadon 3.13+, forcing every Solaris minion into the SmartOS
passwd -sfallback.
New Behavior
Both modules parse
/etc/shadowdirectly via a local_getspnamhelperthat returns an
spwd.struct_spwd-compatible namedtuple. TheSmartOS-style
pwd+passwd -sfallback insolaris_shadowispreserved for the case where
/etc/shadowis not readable.Merge requirements satisfied?
shadow.infois unchanged, only its internal implementation)
changelog/64264.fixed.md; the cherry-picked commitalso keeps its original
changelog/67119.fixed.md)tests/pytests/unit/modules/test_linux_shadow.py,tests/pytests/unit/modules/test_solaris_shadow.py)Commits signed with GPG?
Yes