Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] file.py _get_flags issue #62676

Closed
leifliddy opened this issue Sep 13, 2022 · 5 comments · Fixed by #62677
Closed

[BUG] file.py _get_flags issue #62676

leifliddy opened this issue Sep 13, 2022 · 5 comments · Fixed by #62677
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@leifliddy
Copy link
Contributor

leifliddy commented Sep 13, 2022

Description
Running a simple salt file state results in failure.

Setup
Tested on a physical machine running Fedora 37, python 3.11, and salt v3005 (installed via the Fedora repo)

Steps to Reproduce the behavior
Create the following file:

/srv/salt/dnf-test.sls 

dnf_default_yes:
  file.append:
    - name: /etc/dnf/dnf.conf
    - text: 
      - defaultyes=True

Then run salt-call state.sls dnf-test

This will result in the following error:

[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/salt/state.py", line 2276, in call
    ret = self.states[cdata["full"]](
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 1276, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/states/file.py", line 6431, in append
    if __salt__["file.search"](
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/modules/file.py", line 3141, in search
    return replace(
           ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/modules/file.py", line 2516, in replace
    flags_num = _get_flags(flags)
                ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/salt/modules/file.py", line 1643, in _get_flags
    _flag = getattr(re, str(flag).upper())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 're' has no attribute 'RE.MULTILINE'

Expected behavior
A clear and concise description of what you expected to happen.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3005
 
Dependency Versions:
          cffi: 1.15.1
      cherrypy: Not Installed
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: 4.0.9
     gitpython: 3.1.27
        Jinja2: 3.0.3
       libgit2: 1.3.1
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.4
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.15.0
        pygit2: 1.7.1
        Python: 3.11.0rc1 (main, Aug  9 2022, 00:00:00) [GCC 12.1.1 20220628 (Red Hat 12.1.1-3)]
  python-gnupg: Not Installed
        PyYAML: 6.0
         PyZMQ: 23.2.0
         smmap: 5.0.0
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
System Versions:
          dist: fedora 37 Thirty Seven Prerelease
        locale: utf-8
       machine: x86_64
       release: 5.19.8-300.fc37.x86_64
        system: Linux
       version: Fedora Linux 37 Thirty Seven Prerelease
@leifliddy leifliddy added Bug broken, incorrect, or confusing behavior needs-triage labels Sep 13, 2022
@OrangeDog
Copy link
Contributor

OrangeDog commented Sep 15, 2022

The cause is this change in Python 3.11:

global_enum added – enum decorator to adjust __repr__ and __str__ to show members in the global context – see re.RegexFlag for an example.

which means that str(re.MULTILINE) changes from "MULTILINE" to "re.MULTILINE".

@hartwork
Copy link

@OrangeDog were you able to reproduce the difference in practice? Any ideas why I get identical results for 3.10 and 3.11?:

# python3.10 --version
Python 3.10.8

# python3.10 -c 'import re; print(re.MULTILINE)'
re.MULTILINE

# python3.11 --version
Python 3.11.0

# python3.11 -c 'import re; print(re.MULTILINE)'
re.MULTILINE

gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Jan 30, 2023
…1 hosts

The Python 3.11 issue upstream:
- saltstack/salt#62676
- saltstack/salt#62677

The importlib-metadata issue:
- saltstack/salt#62851
- saltstack/salt#62854

Patches have been extracted from pull requests as following:
- git clone https://github.com/saltstack/salt
- cd salt
- git diff b676e6338a7c094cb3335d11f851ac0e12222017^ 45b924bad865a00116d2e045fe71229f2dc3376e -- salt/utils/entrypoints.py > salt-3005.1-importlib-metadata-5-r1.patch
- git diff 00352ae6e0ed0b80a75ec65cb925dd31a625010d^ 91efaea4975f37de97a88687d40e54e774151a8b -- salt/modules/file.py | head -n 123 > salt-3005.1-modules-file-python-3.11-host.patch

Be sure to call salt-ssh with "--regen-thin" the first time
after updating, to not end up running unpatched 3005.1(-r0) code.

Closes: https://bugs.gentoo.org/875389
Closes: https://bugs.gentoo.org/883671
Signed-off-by: Sebastian Pipping <sping@gentoo.org>
freijon pushed a commit to freijon/gentoo that referenced this issue Jan 31, 2023
…1 hosts

The Python 3.11 issue upstream:
- saltstack/salt#62676
- saltstack/salt#62677

The importlib-metadata issue:
- saltstack/salt#62851
- saltstack/salt#62854

Patches have been extracted from pull requests as following:
- git clone https://github.com/saltstack/salt
- cd salt
- git diff b676e6338a7c094cb3335d11f851ac0e12222017^ 45b924bad865a00116d2e045fe71229f2dc3376e -- salt/utils/entrypoints.py > salt-3005.1-importlib-metadata-5-r1.patch
- git diff 00352ae6e0ed0b80a75ec65cb925dd31a625010d^ 91efaea4975f37de97a88687d40e54e774151a8b -- salt/modules/file.py | head -n 123 > salt-3005.1-modules-file-python-3.11-host.patch

Be sure to call salt-ssh with "--regen-thin" the first time
after updating, to not end up running unpatched 3005.1(-r0) code.

Closes: https://bugs.gentoo.org/875389
Closes: https://bugs.gentoo.org/883671
Signed-off-by: Sebastian Pipping <sping@gentoo.org>
@marmarek
Copy link
Contributor

When is planned next release (3005.2?) with this bug fixed? It makes salt pretty much unusable on systems with Python 3.11 (at least Fedora 37 and Debian bookworm) and new release would help solving this situation.

@hartwork
Copy link

hartwork commented Jan 31, 2023

@marmarek I agree on unusable, and 3005.1 is near four months old now. Probably asking for 3005.2 needs a dedicated issue to be visible.

marmarek added a commit to QubesOS/qubes-salt that referenced this issue Feb 1, 2023
Carry the patch locally, until upstream does new release.
For reference: saltstack/salt#62676

Fixes QubesOS/qubes-issues#7891
marmarek added a commit to QubesOS/qubes-builder that referenced this issue Mar 14, 2023
While salt in dom0 is not affects, it is in Fedora 37. While waiting for
new upstream release (and have it packaged in Fedora), push update
with the patch directly.

saltstack/salt#62676
saltstack/salt#63631
QubesOS/qubes-issues#7891
@nkuttler
Copy link
Contributor

Fwiw

sed -i 's#str(flag).upper#str(flag).replace("re.", "").upper#' /path/to/dist-packages/salt/modules/file.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants