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

pip 24.1b1 downgrade to pip 24.0 throws an exception #12675

Closed
notatallshaw opened this issue May 6, 2024 · 7 comments · Fixed by #12684
Closed

pip 24.1b1 downgrade to pip 24.0 throws an exception #12675

notatallshaw opened this issue May 6, 2024 · 7 comments · Fixed by #12684
Labels
kind: crash For situations where pip crashes type: bug A confirmed bug or unintended behavior

Comments

@notatallshaw
Copy link
Contributor

Description

When you install pip 24.1 beta into Python 3.10 Linux environment and then try to downgrade to pip 24.0 you get an error, although it appears the downgrade works the error is rather unfriendly

Expected behavior

You can downgrade without exception

pip version

24.1b1

Python version

Python 3.10.14

OS

Linux

How to Reproduce

  1. python -m venv .venv
  2. source .venv/bin/activate
  3. python -m pip install pip --upgrade
  4. python -m pip install "pip>=0.0dev0" --upgrade
  5. python -m pip install pip==24.0

Output

$ python -m pip install pip==24.0
Collecting pip==24.0
  Using cached pip-24.0-py3-none-any.whl.metadata (3.6 kB)
Using cached pip-24.0-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 24.1b1
    Uninstalling pip-24.1b1:
      Successfully uninstalled pip-24.1b1
Successfully installed pip-24.0
Traceback (most recent call last):
  File "/home/damian/.pyenv/versions/3.10.14/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/damian/.pyenv/versions/3.10.14/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/__main__.py", line 24, in <module>
    sys.exit(_main())
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/cli/main.py", line 80, in main
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 100, in main
    with self.main_context():
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 234, in _main
    return run(options, args)
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/cli/index_command.py", line 172, in handle_pip_version_check
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/cli/index_command.py", line 136, in _pip_self_version_check
  File "/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/self_outdated_check.py", line 20, in <module>
    from pip._internal.metadata.base import DistributionVersion
ImportError: cannot import name 'DistributionVersion' from 'pip._internal.metadata.base' (/home/damian/opensource/contributions/pip/pip_beta_testing/.venv/lib/python3.10/site-packages/pip/_internal/metadata/base.py)


### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).
@notatallshaw notatallshaw added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels May 6, 2024
@ichard26 ichard26 added kind: crash For situations where pip crashes and removed S: needs triage Issues/PRs that need to be triaged labels May 6, 2024
@ichard26
Copy link
Member

ichard26 commented May 6, 2024

Ugh, this is my fault. #12637 made the pip self-version check import pip._internal.self_outdated_check on demand. This blows up here as it imports the module after the downgrade, which is problematic as the older self-check logic is incompatible with the rest of the pip already loaded into memory.

TL;DR, lazy imports are unsafe when pip reinstalls itself. Solutions are:

I'd prefer option one, but I'll prepare the revert PR as stability is more important.

@notatallshaw
Copy link
Contributor Author

Disable the pip version check when installing pip

Personally I think this makes logical sense anyway. If I am changing the version of pip I don't need pip to tell me that pip is outdated.

@notatallshaw
Copy link
Contributor Author

notatallshaw commented May 6, 2024

And just to double emphasise, the impact is relatively minor here, the downgrade completes:

Successfully installed pip-24.0

The error is thrown after the install.

@ichard26
Copy link
Member

ichard26 commented May 6, 2024

Actually, I guess a valid third option is to suppress all exceptions encountered during the pip self-version check. AFAIK network errors are already suppressed (with a warning).

@ichard26
Copy link
Member

ichard26 commented May 6, 2024

OK I implemented option 1 locally, but one wrinkle is that it doesn't protect source dir downgrades from blowing up. It just blew up as I was running pip install . to test the patch. This is a lot better than nothing as most pip users do not install pip from an unnamed source, but probably still unacceptable.

@uranusjr
Copy link
Member

uranusjr commented May 7, 2024

Maybe we could keep the on-demand imports, but also add a check before installation to see if pip is going to be touched? If pip is going to be modified, we could eagerly import the things that generally need to be on-demand. This way the old modules would already be in memory and should be able to perform correctly.

@ichard26
Copy link
Member

ichard26 commented May 8, 2024

I've implemented option 3 in #12676 and @uranusjr's suggestion in #12684. Please take a look and verify that they actually fix the crash reliably.

@pradyunsg pradyunsg changed the title pip 24.1 downgrade to pip 24.0 throws an exception pip 24.1b1 downgrade to pip 24.0 throws an exception May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: crash For situations where pip crashes type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants