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

22.0: assert len(weights) == expected_node_count AssertionError #10851

Closed
1 task done
elParaguayo opened this issue Jan 30, 2022 · 18 comments · Fixed by #10867
Closed
1 task done

22.0: assert len(weights) == expected_node_count AssertionError #10851

elParaguayo opened this issue Jan 30, 2022 · 18 comments · Fixed by #10867
Labels
type: bug A confirmed bug or unintended behavior
Milestone

Comments

@elParaguayo
Copy link

Description

Hi there,

I'm one of the maintainers for Qtile (https://www.github.com/qtile/qtile).

I've noticed that our docs (hosted by ReadTheDocs) have begun failing to build.

The error message is:

ERROR: Exception:
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/qtile/envs/3274/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 165, in exc_logging_wrapper
    status = run_func(*args)
  File "/home/docs/checkouts/readthedocs.org/user_builds/qtile/envs/3274/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "/home/docs/checkouts/readthedocs.org/user_builds/qtile/envs/3274/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 389, in run
    to_install = resolver.get_installation_order(requirement_set)
  File "/home/docs/checkouts/readthedocs.org/user_builds/qtile/envs/3274/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 190, in get_installation_order
    expected_node_count=len(self._result.mapping) + 1,
  File "/home/docs/checkouts/readthedocs.org/user_builds/qtile/envs/3274/lib/python3.7/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 276, in get_topological_weights
    assert len(weights) == expected_node_count
AssertionError

The first failure (https://readthedocs.org/projects/qtile/builds/15928125/) was the first build following the release of 22.0.

The most recent failure (https://readthedocs.org/projects/qtile/builds/15931046/) also fails on 22.0.1.

Expected behavior

Documents should build successfully.

I'm not aware of any other changes that would have impacted the building of our docs.

pip version

22.0 and 22.0.1

Python version

3.7

OS

ReadTheDocs docker image - I think is Ubuntu 20.04

How to Reproduce

(Appreciate this isn't particularly helpful...)

  1. Submit a PR for Qtile
  2. Hook starts build of docs
  3. Build fails

Note: I cannot recreate locally. However, given that the failures started with 22.0 I can only assume it's caused by that. Unfortunately, I don't know what the error message means.

Output

No response

Code of Conduct

@elParaguayo elParaguayo added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jan 30, 2022
@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Jan 30, 2022
@pradyunsg
Copy link
Member

This is likely related to #10574.

/cc @mauritsvanrees in case they're interested!

@pradyunsg
Copy link
Member

pradyunsg commented Jan 30, 2022

@elParaguayo Can you try creating a clean virtualenv, and running pip install -r doc/requirements.txt in it, on a compatible system, with that project? If you can confirm that's a reproducer, that'd be great! ^>^

@pradyunsg pradyunsg changed the title Pip update to 22.0 (and 22.0.1) resulting in failed builds on ReadTheDocs assert len(weights) == expected_node_count AssertionError 22.0: assert len(weights) == expected_node_count AssertionError Jan 30, 2022
@elParaguayo
Copy link
Author

I tried that. I create a virtual environment with python 3.7, upgraded pip to latest and installed requirements. No error message.

I was hoping to get the same error locally.

@pradyunsg
Copy link
Member

pradyunsg commented Jan 30, 2022

Hmmm... Maybe this needs running the pip install commands that RTD runs before those?

pip install --upgrade pip setuptools<58.3.0 
pip install --upgrade mock==1.0.1 pillow==5.4.1 alabaster>=0.7,<0.8,!=0.7.5 commonmark==0.8.1 recommonmark==0.5.0 sphinx<2 sphinx-rtd-theme<0.5 readthedocs-sphinx-ext<2.2 
pip install -r docs/requirements.txt

It might be that already-installed packages are implicated.

@boxed
Copy link

boxed commented Jan 31, 2022

This started happening to me too.

@notatallshaw
Copy link
Contributor

notatallshaw commented Jan 31, 2022

Hmmm... Maybe this needs running the pip install commands that RTD runs before those?

pip install --upgrade pip setuptools<58.3.0 
pip install --upgrade mock==1.0.1 pillow==5.4.1 alabaster>=0.7,<0.8,!=0.7.5 commonmark==0.8.1 recommonmark==0.5.0 sphinx<2 sphinx-rtd-theme<0.5 readthedocs-sphinx-ext<2.2 
pip install -r docs/requirements.txt

It might be that already-installed packages are implicated.

I am able to reproduce the error following these steps with a fresh virtual environment. Here are the steps specifically:

python3.10 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip "setuptools<58.3.0"
python -m pip install --upgrade mock==1.0.1 pillow==5.4.1 "alabaster>=0.7,<0.8,!=0.7.5" commonmark==0.8.1 recommonmark==0.5.0 "sphinx<2" "sphinx-rtd-theme<0.5" "readthedocs-sphinx-ext<2.2"
python -m pip install -r requirements.txt

And the requirements file looks like this:

setuptools_scm
sphinx
sphinx_rtd_theme
funcparserlib==1.0.0a0
sphinxcontrib-seqdiag
numpydoc
cairocffi >= 0.9.0
cffi >= 1.1.0
xcffib >= 0.10.1

I have not been able to reproduce it using a single install or using download.

I set a breakpoint where the asert statement is and I found:

(Pdb) expected_node_count
41
(Pdb) len(weights)
42
(Pdb) weights
{'snowballstemmer': 41, 'urllib3': 41, 'alabaster': 41, 'pytz': 41, 'six': 41, 'pyparsing': 41, 'imagesize': 41, '<Python from Requires-Python>': 41, 'pygments': 41, 'pillow': 41, 'charset-normalizer': 41, 'docutils': 41, 'certifi': 41, 'setuptools': 41, 'markupsafe': 41, 'sphinxcontrib-serializinghtml': 41, 'idna': 41, 'packaging': 24, 'funcparserlib': 24, 'sphinxcontrib-websupport': 24, 'webcolors': 24, 'pycparser': 24, 'sphinxcontrib-qthelp': 24, 'sphinxcontrib-htmlhelp': 24, 'babel': 24, 'sphinxcontrib-applehelp': 24, 'tomli': 24, 'requests': 24, 'sphinxcontrib-devhelp': 24, 'sphinxcontrib-jsmath': 24, 'jinja2': 24, 'cffi': 10, 'sphinx': 10, 'setuptools-scm': 10, 'blockdiag': 10, 'cairocffi': 6, 'sphinx-rtd-theme': 6, 'numpydoc': 6, 'seqdiag': 6, 'xcffib': 6, 'sphinxcontrib-seqdiag': 1, None: 0}

@mauritsvanrees
Copy link
Sponsor Contributor

I can't easily check the example, because installing Pillow fails due to missing zlib. I should have that installed, and I have various Pillow versions installed correctly, but I get this error more often.

The expected_node_count is defined as len(self._result.mapping) + 1. Can someone post which items are in self._result.mapping? If we see which one is missing from weights, this would help.

This one in weights looks suspicious: <Python from Requires-Python>.

BTW, if someone is looking for a workaround, you could try an extra option for pip install: --use-deprecated legacy-resolver. I don't know if it helps, but it may be worth a try.

@elParaguayo
Copy link
Author

FYI - ReadTheDocs are pinning pip to 21.3.1 for now.

readthedocs/readthedocs.org#8864 (comment)

@notatallshaw
Copy link
Contributor

notatallshaw commented Jan 31, 2022

The expected_node_count is defined as len(self._result.mapping) + 1. Can someone post which items are in self._result.mapping? If we see which one is missing from weights, this would help.

This was a fun little learning exercise with the debugger (I've removed the parts where I'm figuring out how to do this):

> /home/damian/nodebug/pip/src/pip/_internal/resolution/resolvelib/resolver.py(278)get_topological_weights()
-> assert weights[None] == 0
(Pdb) u
> /home/damian/nodebug/pip/src/pip/_internal/resolution/resolvelib/resolver.py(188)get_installation_order()
-> weights = get_topological_weights(
(Pdb) globals()['result_mapping'] = self._result.mapping
(Pdb) d
> /home/damian/nodebug/pip/src/pip/_internal/resolution/resolvelib/resolver.py(278)get_topological_weights()
-> assert weights[None] == 0
(Pdb) len(weights)
42
(Pdb) len(result_mapping)
40
(Pdb) weights - result_mapping.keys()
{'sphinxcontrib-websupport', None}

So "sphinxcontrib-websupport" is in the weights but not in the self._result.mapping.

JacobCallahan added a commit to SatelliteQE/robottelo that referenced this issue Jan 31, 2022
pip 22 is currently having issues with dependency installation (pypa/pip#10851)
until it is resolved, we should disable explicit updating. if it takes longer to resolve, then we may need to explicitly enforce pip 21.3.1
@pradyunsg
Copy link
Member

See #9031, which also involved sphinxcontrib-websupport.

mshriver pushed a commit to SatelliteQE/robottelo that referenced this issue Jan 31, 2022
* Temporarily Stop Updating pip

pip 22 is currently having issues with dependency installation (pypa/pip#10851)
until it is resolved, we should disable explicit updating. if it takes longer to resolve, then we may need to explicitly enforce pip 21.3.1

* Temporarily disable pip in merge_to_master
@notatallshaw
Copy link
Contributor

notatallshaw commented Jan 31, 2022

See #9031, which also involved sphinxcontrib-websupport.

That looks horrendous... And given the steps required to produce this error it's probably a very similar issue.

Perhaps the graph cleaning assumes you can't have nodes which are not descendants of the root node? Which appears like it can still be the case reading that issue?

@AllexVeldman
Copy link

For completeness, this is also raised when running pip install tox tox-gh probably due to tox-gh pinning tox to an alpha release (4.0.0a10), resulting in 2 versions of tox.

In previous releases of pip this would install the dependency defined by tox-gh.

Removing tox from the install command solves this instance.

@mauritsvanrees
Copy link
Sponsor Contributor

I confirm that this can be reproduced with the original instructions of issue #9031. Updated for pip 22:

pip install -U pip
pip install sphinx==1.8.5
pip install sphinx sphinxcontrib-bibtex

In this case, before calculating the topological weights:

(Pdb) len(graph)
34
(Pdb) len(self._result.mapping)
32
(Pdb) set(graph) - set(self._result.mapping)
{'sphinxcontrib-websupport', None}
(Pdb) len(req_set.requirements.keys())
14
(Pdb) req_set.requirements.keys()
odict_keys(['sphinxcontrib-bibtex', 'sphinx', 'docutils', 'importlib-metadata', 'pybtex', 'pybtex-docutils', 'sphinxcontrib-htmlhelp', 'sphinxcontrib-applehelp', 'sphinxcontrib-devhelp', 'sphinxcontrib-jsmath', 'sphinxcontrib-qthelp', 'latexcodec', 'pyyaml', 'zipp'])

Some ideas:

  • Several values in self._result.mapping are instances of the class pip._internal.resolution.resolvelib.candidates.AlreadyInstalledCandidate. Can we ignore these? They are installed already, so they don't need to be installed anymore. But maybe these are older versions from packages that we want to upgrade, or reinstall? (If we cannot ignore them, then maybe already installed candidates should get the highest possible weight, but that won't solve the current issue.)
  • get_topological_weights is only used to define the sort order of req_set.requirements.items(). As you can see in the short pdb session above, this only contains 14 keys. So the weights must exactly these 14, and we can ignore all others. That should simplify things.

When I try the last idea, it works for pip install sphinx sphinxcontrib-bibtex.
I can try a PR.

@pradyunsg
Copy link
Member

pradyunsg commented Jan 31, 2022

Perhaps the graph cleaning assumes you can't have nodes which are not descendants of the root node? Which appears like it can still be the case reading that issue?

The graph cleaning "trims" nodes that don't have any edges "out" of them. This makes it so that the graph is only left with cycles by the time we recursive visit logic that is keeps track of paths and visits every possible path, which makes the whole thing a lot quicker.

That won't be affected by the root cause of this failure, which originates from resolvelib not spewing out the right keys in the mapping object. Anyway, this is an easy fix -- change the assertion to assume that the weighted graph will be the same length as the graph put into the topological sort. 🤷🏽

@mauritsvanrees
Copy link
Sponsor Contributor

This PR should fix it: #10867

@mauritsvanrees
Copy link
Sponsor Contributor

For completeness, this is also raised when running pip install tox tox-gh probably due to tox-gh pinning tox to an alpha release (4.0.0a10), resulting in 2 versions of tox.

In previous releases of pip this would install the dependency defined by tox-gh.

With pip 22.0.2, I also see this error. With my PR it works again, resulting in an install of tox 4.0.0a10.

peterdragun pushed a commit to peterdragun/robottelo that referenced this issue Feb 2, 2022
pip 22 is currently having issues with dependency installation (pypa/pip#10851)
until it is resolved, we should disable explicit updating. if it takes longer to resolve, then we may need to explicitly enforce pip 21.3.1
duncanmmacleod added a commit to duncanmmacleod/gwpy that referenced this issue Feb 2, 2022
duncanmmacleod added a commit to duncanmmacleod/gwpy that referenced this issue Feb 2, 2022
JacobCallahan added a commit to SatelliteQE/robottelo that referenced this issue Feb 2, 2022
pip 22 is currently having issues with dependency installation (pypa/pip#10851)
until it is resolved, we should disable explicit updating. if it takes longer to resolve, then we may need to explicitly enforce pip 21.3.1
mr-c added a commit to rabix/sbpack that referenced this issue Feb 2, 2022
mr-c added a commit to rabix/sbpack that referenced this issue Feb 2, 2022
avoid broken pip versions due to pypa/pip#10851
@Secunseen
Copy link

So can anyone help me out with 22.0.3

@notatallshaw
Copy link
Contributor

So can anyone help me out with 22.0.3

This issue is closed. If you have a new issue with the latest version of pip (currently 22.0.3) you should report that new issue.

inmantaci pushed a commit to inmanta/inmanta-core that referenced this issue Feb 14, 2022
Bumps [pip](https://github.com/pypa/pip) from 21.3.1 to 22.0.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>22.0.3 (2022-02-03)</h1>
<h2>Features</h2>
<ul>
<li>Print the exception via <code>rich.traceback</code>, when running with <code>--debug</code>. (<code>[#10791](pypa/pip#10791) &lt;https://github.com/pypa/pip/issues/10791&gt;</code>_)</li>
</ul>
<h2>Bug Fixes</h2>
<ul>
<li>
<p>Only calculate topological installation order, for packages that are going to be installed/upgraded.</p>
<p>This fixes an <code>AssertionError</code> that occured when determining installation order, for a very specific combination of upgrading-already-installed-package + change of dependencies + fetching some packages from a package index. This combination was especially common in Read the Docs' builds. (<code>[#10851](pypa/pip#10851) &lt;https://github.com/pypa/pip/issues/10851&gt;</code>_)</p>
</li>
<li>
<p>Use <code>html.parser</code> by default, instead of falling back to <code>html5lib</code> when <code>--use-deprecated=html5lib</code> is not passed. (<code>[#10869](pypa/pip#10869) &lt;https://github.com/pypa/pip/issues/10869&gt;</code>_)</p>
</li>
</ul>
<h2>Improved Documentation</h2>
<ul>
<li>Clarify that using per-requirement overrides disables the usage of wheels. (<code>[#9674](pypa/pip#9674) &lt;https://github.com/pypa/pip/issues/9674&gt;</code>_)</li>
</ul>
<h1>22.0.2 (2022-01-30)</h1>
<h2>Deprecations and Removals</h2>
<ul>
<li>Instead of failing on index pages that use non-compliant HTML 5, print a deprecation warning and fall back to <code>html5lib</code>-based parsing for now. This simplifies the migration for non-compliant index pages, by letting such indexes function with a warning. (<code>[#10847](pypa/pip#10847) &lt;https://github.com/pypa/pip/issues/10847&gt;</code>_)</li>
</ul>
<h1>22.0.1 (2022-01-30)</h1>
<h2>Bug Fixes</h2>
<ul>
<li>Accept lowercase <code>&lt;!doctype html&gt;</code> on index pages. (<code>[#10844](pypa/pip#10844) &lt;https://github.com/pypa/pip/issues/10844&gt;</code>_)</li>
<li>Properly handle links parsed by html5lib, when using <code>--use-deprecated=html5lib</code>. (<code>[#10846](pypa/pip#10846) &lt;https://github.com/pypa/pip/issues/10846&gt;</code>_)</li>
</ul>
<h1>22.0 (2022-01-29)</h1>
<h2>Process</h2>
<ul>
<li>Completely replace :pypi:<code>tox</code> in our development workflow, with :pypi:<code>nox</code>.</li>
</ul>
<p>Deprecations and Removals</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/44018de50cafba25445a225c1a1986d6312e1ef3"><code>44018de</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/65f096c432d60d5f0214793becd592e1c1c3b624"><code>65f096c</code></a> Update AUTHORS.txt</li>
<li><a href="https://github.com/pypa/pip/commit/7d50964bcb1b25f9fe2c49fe447ab58aad2b4247"><code>7d50964</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10876">#10876</a> from mbacchi/vcs_support_typo</li>
<li><a href="https://github.com/pypa/pip/commit/ff8dbb458a59905c5462d339a63536257aad497a"><code>ff8dbb4</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10867">#10867</a> from mauritsvanrees/maurits-topoligical-weights-req...</li>
<li><a href="https://github.com/pypa/pip/commit/b3f5cad73241e25a25ce7d50eb9175dbafcfd8db"><code>b3f5cad</code></a> Update news/10851.bugfix.rst</li>
<li><a href="https://github.com/pypa/pip/commit/cf4655f474cb8a04fa6b274ee0edaf774546a79b"><code>cf4655f</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10869">#10869</a> from pradyunsg/put-html5lib-behind-flag</li>
<li><a href="https://github.com/pypa/pip/commit/3608b42ef0ab39a2d50335356644f8f3464f651a"><code>3608b42</code></a> Fix minor typo in vcs support doc</li>
<li><a href="https://github.com/pypa/pip/commit/6c92a33b6e22f099edac8f4df594ffe6a18eb6e2"><code>6c92a33</code></a> Place the link as &quot;context&quot; instead of &quot;Link:&quot;</li>
<li><a href="https://github.com/pypa/pip/commit/7a3b0f1ae1cc59ae6566694e47887728a7976ab9"><code>7a3b0f1</code></a> 📰</li>
<li><a href="https://github.com/pypa/pip/commit/d7fed8fe9382c4f4442d7aa6216f41c8ed6f1ea3"><code>d7fed8f</code></a> Use rich.traceback with debug mode (<a href="https://github-redirect.dependabot.com/pypa/pip/issues/10832">#10832</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/pypa/pip/compare/21.3.1...22.0.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.3.1&new-version=22.0.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 Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
7 participants