saltstack / saltstack/salt

[BUG] DeprecationWarning in salt/modules/file.py: 'count' passed as positional argument to re.subn on Python 3.13+ / 3.14

Open Beginner friendly
#69,843 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

https://github.com/saltstack/salt/blob/c8f7e9ab9b833333ac9d8d3d16e31878c58aab3e/salt/modules/file.py#L2837

Description

When running salt-call or applying states on nodes running Python 3.13 or Python 3.14, a DeprecationWarning is emitted to stderr from salt/modules/file.py:

/opt/saltstack/salt/lib/python3.14/site-packages/salt/modules/file.py:2833: DeprecationWarning: 'count' is passed as positional argument
  result, nrepl = re.subn(

Python 3.13+ / 3.14 deprecates passing count as the 4th positional argument to re.subn() (and re.sub()), requiring keyword arguments instead.

Steps to Reproduce
  1. Run salt-call --local state.apply on an environment running Python 3.13+ / 3.14.
  2. Observe stderr output during file state replacements.
Expected Behavior

file.replace and internal string replacements in salt/modules/file.py should execute cleanly without emitting Python DeprecationWarning messages.

Actual Behavior

The following deprecation warning is printed to stderr:

/opt/saltstack/salt/lib/python3.14/site-packages/salt/modules/file.py:2833: DeprecationWarning: 'count' is passed as positional argument
  result, nrepl = re.subn(
Proposed Fix

In salt/modules/file.py (around line 2833), update the re.subn call to pass count as a keyword argument (count=count):

-                result, nrepl = re.subn(
-                    cpattern,
-                    repl.replace(b"\\", b"\\\\") if backslash_literal else repl,
-                    r_data,
-                    count,
-                )
+                result, nrepl = re.subn(
+                    cpattern,
+                    repl.replace(b"\\", b"\\\\") if backslash_literal else repl,
+                    r_data,
+                    count=count,
+                )
Environment
  • Salt Version: 3008.2+
  • Python Version: 3.13 / 3.14

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/modules/file.py around line 2833 and reproduce file replacement on Python 3.13 or 3.14 to confirm the warning. Update the re.subn call so count is passed by keyword, then verify that file.replace and related internal replacements run without the DeprecationWarning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.