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

Vendoring of tenacity is leaky #10020

Closed
bdarnell opened this issue May 27, 2021 · 11 comments · Fixed by #10029
Closed

Vendoring of tenacity is leaky #10020

bdarnell opened this issue May 27, 2021 · 11 comments · Fixed by #10029
Labels
project: vendored dependency Related to a vendored dependency type: bug A confirmed bug or unintended behavior
Milestone

Comments

@bdarnell
Copy link
Contributor

Description

Tenacity contains a conditional import of tornado. This makes the behavior of pip sensitive to third-party packages outside of its vendor directory. Specifically, if a version of tornado that does not include the tornado.gen.sleep function is installed, pip will fail to start. (This is unlikely since this function has been around a long time and we have no plans of deprecating it or removing it. But we do have a report of this happening in tornadoweb/tornado#3034)

Expected behavior

Pip should not be affected by the presence or absence of any other third-party packages. Any conditional imports in its vendored dependencies should be modified to unconditionally fail (e.g. replace the above-linked block with tornado = None).

pip version

21.1.2

Python version

3.8

OS

linux

How to Reproduce

  1. pip install tornado==4.0.0
  2. pip --version

Output

~/ImpressionableVoluminousCategories$ pip --version
pip 21.1.2 from /opt/virtualenvs/python3/lib/python3.8/site-packages/pip (python 3.8)
~/ImpressionableVoluminousCategories$ pip install tornado==4.0.0
Collecting tornado==4.0.0
  Downloading tornado-4.0.tar.gz (313 kB)
     |████████████████████████████████| 313 kB 4.5 MB/s 
Requirement already satisfied: certifi in /opt/virtualenvs/python3/lib/python3.8/site-packages (from tornado==4.0.0) (2020.12.5)
Building wheels for collected packages: tornado
  Building wheel for tornado (setup.py) ... done
  Created wheel for tornado: filename=tornado-4.0-cp38-cp38-linux_x86_64.whl size=344556 sha256=d9c5e6911e5bdac5b90db4b33d01891562365e235396bd336380dd45cb61a9b7
  Stored in directory: /home/runner/.cache/pip/wheels/9a/d7/93/a846246f95067512a78899329bdb84a695d693e67c28a4e71f
Successfully built tornado
Installing collected packages: tornado
Successfully installed tornado-4.0
~/ImpressionableVoluminousCategories$ pip --version
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/cli/parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/configuration.py", line 27, in <module>
    from pip._internal.utils.misc import ensure_dir, enum
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 38, in <module>
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/tenacity/__init__.py", line 523, in <module>
    from pip._vendor.tenacity.tornadoweb import TornadoRetrying
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/tenacity/tornadoweb.py", line 26, in <module>
    class TornadoRetrying(BaseRetrying):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pip/_vendor/tenacity/tornadoweb.py", line 27, in TornadoRetrying
    def __init__(self, sleep=gen.sleep, **kwargs):
AttributeError: module 'tornado.gen' has no attribute 'sleep'
~/ImpressionableVoluminousCategories$ 


### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).
@uranusjr
Copy link
Member

Thanks for raising the issue. I think an easy way would be to vendor a patch to delete those imports. We already have a few of those here. Would you be interested in contributing one for this?

@uranusjr uranusjr added project: vendored dependency Related to a vendored dependency and removed S: needs triage Issues/PRs that need to be triaged labels May 27, 2021
bdarnell pushed a commit to bdarnell/pip that referenced this issue May 28, 2021
Code depending on this conditional import could break if an old
version of Tornado is present in the environment, rendering pip
unusable.

Fixes pypa#10020
@bdarnell
Copy link
Contributor Author

Sure: #10029

@pradyunsg
Copy link
Member

@sbidoul do you think this is important enough for a bugfix release? 😅

@pfmoore
Copy link
Member

pfmoore commented May 28, 2021

Is this a new problem that was introduced in 21.1, or has it been around for a while and just not been noticed before? If it's not a new problem, I doubt it's worth a bugfix release (although it's the RM's call). If it is a new issue, I'm still ambivalent - it seems pretty rare in practice 🤷

@bdarnell
Copy link
Contributor Author

It appears to be new in 21.1 (introduced in 64ecfc8). It is indeed rare (it requires using a version of Tornado from before Feb 2015), but it has happened and when it happens it breaks things in a way that you can't really recover from without blowing away the virtualenv. (but overall I'm ambivalent too - personally I'd probably wait for a second occurrence before starting a release).

@pfmoore
Copy link
Member

pfmoore commented May 28, 2021

Ah yes, I'd forgotten we'd switched libraries. But equally, it's worth remembering that 21.2 isn't that far off (July) so we're not talking about a huge delay either way.

@pradyunsg
Copy link
Member

Well, if someone else hits this, it'd probably make sense to expidite this. Otherwise, we'll leave it be until the next release.

bdarnell pushed a commit to bdarnell/pip that referenced this issue May 29, 2021
Code depending on this conditional import could break if an old
version of Tornado is present in the environment, rendering pip
unusable.

Fixes pypa#10020
bdarnell pushed a commit to bdarnell/pip that referenced this issue May 29, 2021
Code depending on this conditional import could break if an old
version of Tornado is present in the environment, rendering pip
unusable.

Fixes pypa#10020
@bdarnell
Copy link
Contributor Author

FYI we've had a second commenter on tornadoweb/tornado#3034 so it does look like this is affecting more than one person.

@pradyunsg
Copy link
Member

Heyo @bdarnell! Gentle nudge to not mention the issue link/number in the commit message.

That results in a lot of spam in this issue, as people rebase that PR or cherry pick changes or just do anything with that commit on GitHub.

@bdarnell
Copy link
Contributor Author

Ah, OK, I can remove that if I have to update the commit again. I'm well aware of the spam that can come from an @username mention in a commit message, but most of the projects I've contributed to embrace the commit-message-to-issue linking.

@sbidoul sbidoul added this to the 21.1.3 milestone May 31, 2021
@Eeyhan
Copy link

Eeyhan commented Jun 22, 2021

I just solve,If you want to solve this problem quickly,pull down the git source code for Tornado>=4.0 and above and install it with the command:
python setup.py install

inmantaci added a commit to inmanta/inmanta-core that referenced this issue Jun 28, 2021
Bumps [pip](https://github.com/pypa/pip) from 21.1.2 to 21.1.3.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p>
<blockquote>
<h1>21.1.3 (2021-06-26)</h1>
<h2>Bug Fixes</h2>
<ul>
<li>Remove unused optional <code>tornado</code> import in vendored <code>tenacity</code> to prevent old versions of Tornado from breaking pip. (<code>[#10020](pypa/pip#10020) &lt;https://github.com/pypa/pip/issues/10020&gt;</code>_)</li>
<li>Require <code>setup.cfg</code>-only projects to be built via PEP 517, by requiring an explicit dependency on setuptools declared in pyproject.toml. (<code>[#10031](pypa/pip#10031) &lt;https://github.com/pypa/pip/issues/10031&gt;</code>_)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/e69a8f3987f44178dec8b9137158b4a6ed778ca3"><code>e69a8f3</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/c141edc5c90d0e3c2f40635516f151e2d02b5d95"><code>c141edc</code></a> remove support for setup.cfg only projects</li>
<li><a href="https://github.com/pypa/pip/commit/363e90b62c3bfff14a4684545d54300007bb4d78"><code>363e90b</code></a> Avoid importing a non-vendored version of Tornado</li>
<li><a href="https://github.com/pypa/pip/commit/4cab55f48ef2d05da40dd603910a68f81523ddd4"><code>4cab55f</code></a> Rephrase the warning printed when run as root on Unix</li>
<li>See full diff in <a href="https://github.com/pypa/pip/compare/21.1.2...21.1.3">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=21.1.2&new-version=21.1.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
project: vendored dependency Related to a vendored dependency type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants