Skip to content

Catch misleading ImportError #5098

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

Closed
wants to merge 2 commits into from
Closed

Catch misleading ImportError #5098

wants to merge 2 commits into from

Conversation

higs4281
Copy link

If pip cache gets out of sync with the Python version used to create
it, it can cause a misleading pickling error.

When serialize.py tries to deserialize pickled cache data, packages
with an out-of-date path will generate an ImportError that may refer to
any number of imports that can look like missing external packages,
such as urllib3 or requests. Example:

File "/Users/higgins/Projects/cfgov-refresh/.tox/unittest-fast/lib/python2.7/site-packages/pip/_vendor/cachecontrol/serialize.py",line 168, in _loads_v1
cached = pickle.loads(data)
ImportError: No module named urllib3._collections

In this state, attempting to load a cached package in any local virtual environment
will hit an import error that doesn't seem related. Also, tox tests that generate
a new environment will also bomb if they try to install a cached package.

Adding ImportError as an exception lets a user escape this state
by skipping the cache, the way a ValueError does.

It appears this commenter on #5079 encountered the same pickling error.

Users who realize it's a cache problem can use --no-cache-dir on all
their installs, or clear the system pip cache, but a self-healing solution
would help toilers like me.

If pip cache data get out of sync with the Python version used to create
them, it can cause a misleading pickling error.

When serialize.py tries to deserialize pickled cache data, packages
with an out-of-date path will generate an ImportError that may refer to
any number of imports, some of which can be paths that look
like external packages, such as urllib3 or requests. Example:

```
File "/Users/higgins/Projects/cfgov-refresh/.tox/unittest-fast/lib/python2.7/site-packages/pip/_vendor/cachecontrol/serialize.py",line 168, in _loads_v1
cached = pickle.loads(data)
ImportError: No module named urllib3._collections
```

It can be hard to understand and get out of this state, because attempting
to load a cached package in any local virtual environment will hit an
import error that doesn't seem related. Also, tox tests that generate
a new environment will also bomb if they try to install a cached package.

Adding ImportError as an exception allows a user to get out of this
state by skipping the cache, the way a ValueError does, and allows
the cache to get back in sync for users who have upgraded Python.

It appears [this commenter](#5079 (comment)) on #5079 encountered the same pickling error.

Users who realize it's a cache problem can use `--no-cache-dir` on all
their installs, or clear the system pip cache, but a self-healing solution
would help toilers like me.
@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 11, 2018
@pradyunsg
Copy link
Member

Hey @higs4281! Sorry for the delay in responding to this PR.

This is a fix in an vendored dependency cachecontrol. You'd want to make this fix over at https://github.com/ionrock/cachecontrol, which when released would be brought into pip via an update of the dependency.

@higs4281
Copy link
Author

Ah -- thanks for the explanation. I'll close.

@higs4281 higs4281 closed this Jun 13, 2018
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants