pip: AttributeError: 'NoneType' object has no attribute 'is_hash_allowed'

Environment

  • pip version: 19.2
  • Python version: 3.6.8
  • OS: Mac OSX (Darwin Kernel Version 18.6.0)

Description I made env update in my project including pip as well. After that I wanted to check outdated packages with command:

pip list --outdated --format=columns

After that exception was raised.

Expected behavior I expected list of packages or empty list.

How to Reproduce

  1. Get the newest version of package from PyPI.
  2. Then run pip list --outdated --format=columns
  3. An error occurs.

Output

(env) project (develop) $ pip list --outdated --format=columns
ERROR: Exception:
Traceback (most recent call last):
  File "/project/env/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 188, in main
    status = self.run(options, args)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 156, in run
    packages = self.get_outdated(packages, options)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 164, in get_outdated
    dist for dist in self.iter_packages_latest_infos(packages, options)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 164, in <listcomp>
    dist for dist in self.iter_packages_latest_infos(packages, options)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 195, in iter_packages_latest_infos
    best_candidate = evaluator.get_best_candidate(all_candidates)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/index.py", line 729, in get_best_candidate
    best_candidate = max(candidates, key=self._sort_key)
  File "/project/env/lib/python3.6/site-packages/pip/_internal/index.py", line 710, in _sort_key
    has_allowed_hash = int(link.is_hash_allowed(self._hashes))
  File "/project/env/lib/python3.6/site-packages/pip/_internal/models/link.py", line 213, in is_hash_allowed
    return hashes.is_hash_allowed(self.hash_name, hex_digest=self.hash)
AttributeError: 'NoneType' object has no attribute 'is_hash_allowed'

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 40
  • Comments: 18 (12 by maintainers)

Most upvoted comments

The fix is in master. I’ll do the release in a bit – getting a bit of rest after a long day today.

The release with this bug-fix has been uploaded. Thanks everyone (and especially @cjerdonek)! 😃

Thanks for the confirmation of this occurring on multiple OSes!

Folks, if you’re facing the same issue, please don’t post additional comments. Please use GitHub reactions to upvote the first post and subscribe to the issue.

That way the maintainers would be able to have a discussion on how to resolve this in this issue – additional “me too” comments won’t help anyone.

Same issue on Windows 10, Python 3.7.3

And even though models/link.py where the function is defined does have strict_optional enabled.

Yea - mypy does checks at the call site, using the rules at the call site.


Your suggested fix and PR look good to me. If we don’t see any other issue come up, I can do the bugfix release in the evening today – ~3-5 hours from now.

If we don’t see any other issue come up, I can do the bugfix release in the evening today – ~3-5 hours from now.

That would be great. Thank you so much for doing that.

This issue tells me that a good step after this (for 19.3 – not the patch release) will be to get strict_optional turned on for index.py