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

Fix 'PathDistribution' object has no attribute '_normalized_name' - Issue 61062 #61064

Merged
merged 2 commits into from Oct 21, 2021

Conversation

piterpunk
Copy link

What does this PR do?

salt/utils/entrypoints.py was changed to use importlib.metadata when Python version is equal or higher than 3.10. For other cases, it uses importlib_metadata provided by Salt. But, in salt/_compat.py it always uses the importlib_metadata from Salt, which causes an exception.

This PR changes salt/_compat.py to use the same logic as salt/utils/entrypoints.py to choose between importlib.metadata or importlib_metadata.

What issues does this PR fix or reference?

Fixes: #61062

Previous Behavior

Salt commands execution fails with:

Traceback (most recent call last):
  File "/usr/lib64/python3.10/site-packages/salt/utils/parsers.py", line 210, in parse_args
    mixin_after_parsed_func(self)
  File "/usr/lib64/python3.10/site-packages/salt/utils/parsers.py", line 887, in __setup_extended_logging
    log.setup_extended_logging(self.config)
  File "/usr/lib64/python3.10/site-packages/salt/log/setup.py", line 414, in setup_extended_logging
    providers = salt.loader.log_handlers(opts)
  File "/usr/lib64/python3.10/site-packages/salt/loader/__init__.py", line 686, in log_handlers
    _module_dirs(
  File "/usr/lib64/python3.10/site-packages/salt/loader/__init__.py", line 148, in _module_dirs
    for entry_point in entrypoints.iter_entry_points("salt.loader"):
  File "/usr/lib64/python3.10/site-packages/salt/utils/entrypoints.py", line 43, in _wrapped
    return f(*args, **kwargs)
  File "/usr/lib64/python3.10/site-packages/salt/utils/entrypoints.py", line 55, in iter_entry_points
    entry_points = importlib.metadata.entry_points()
  File "/usr/lib64/python3.10/importlib/metadata/__init__.py", line 971, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "/usr/lib64/python3.10/importlib/metadata/__init__.py", line 429, in load
    ordered = sorted(eps, key=by_group)
  File "/usr/lib64/python3.10/importlib/metadata/__init__.py", line 968, in <genexpr>
    eps = itertools.chain.from_iterable(
  File "/usr/lib64/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
    k = key(element)
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'

New Behavior

Salt commands runs without AttributeError: 'PathDistribution' object has no attribute '_normalized_name' error

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

piterpunk added 2 commits October 15, 2021 12:28
Use the same logic in _compat.py and entrypoints.py to load
the same importlib.metadata. Python's built in implementation for
Python >= 3.10 and the Salt one for others.
@piterpunk piterpunk requested a review from a team as a code owner October 15, 2021 15:43
@piterpunk piterpunk requested review from garethgreenaway and removed request for a team October 15, 2021 15:43
@saltstack saltstack deleted a comment Oct 20, 2021
@Ch3LL Ch3LL merged commit cdf0e96 into saltstack:master Oct 21, 2021
@piterpunk piterpunk deleted the fix_importlib_python310 branch November 30, 2021 13:49
algitbot pushed a commit to alpinelinux/aports that referenced this pull request Dec 30, 2021
saltstack-formulas-github pushed a commit to netmanagers/salt-image-builder that referenced this pull request Mar 29, 2022
@vzhestkov vzhestkov mentioned this pull request Apr 5, 2022
3 tasks
@chenrui333
Copy link

chenrui333 commented Apr 17, 2022

Just curious. When is this going to be released?

@Vaelatern
Copy link
Contributor

I hope this makes it into 3004.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Error when running Salt 3004rc1 with Python 3.10
7 participants