Skip to content

uv, python: leave out blank index URLs before looking up hashes - #16945

Open
nikgerling wants to merge 2 commits into
dependabot:mainfrom
nikgerling:fix/uv-python-blank-index-url
Open

nikgerling wants to merge 2 commits into
dependabot:mainfrom
nikgerling:fix/uv-python-blank-index-url

Conversation

@nikgerling

Copy link
Copy Markdown

What are you trying to accomplish?

Fixes #12260: some Python packages fail to update with ValueError: unknown url type: '/pypi/<name>/json' when the requirements file is compiled with hashes. The uv ecosystem (uv pip compile --generate-hashes) fails the same way as pip.

FileUpdater#pip_compile_index_urls (identical in uv and python) passes every credential of the job through AuthedUrlBuilder.authed_url. A credential without an index-url, such as the github.com git_source credential, gives "", so the list becomes [nil, ""]. CompileFileUpdater#package_hashes_for then does args << index_url if index_url. Because "" is truthy, hashin builds "" + "/pypi/<name>/json". That ValueError is not a PackageNotFoundError, so it is re-raised and the dependency is left out of the update.

Only some packages hit this. package_hashes_for is reached through update_hashes_if_required, which runs only when a package's new version has fewer hashes than the old one. That happens when the new release, or something it pulls in, ships fewer distribution files. Examples: hypothesis 6.168.5 → 6.170.15, and import-linter 2.15 → 2.16 (which pulls grimp 3.17 → 3.20).

Anything you want to highlight for special attention from reviewers?

The change drops blank URLs where the list is built, in both ecosystems. The other option was to treat "" like nil in package_hashes_for. That would query the default index twice and add every hash twice. A credential with an index-url is unaffected, and so is the replaces-base branch.

How will you know you've accomplished your goal?

  • A new spec in uv/spec/dependabot/uv/file_updater_spec.rb and in python/spec/dependabot/python/file_updater_spec.rb uses a real git_source credential and a real python_index credential. It expects [nil, "https://pypi.example.com/simple"], where the code before this change returned [nil, "", "https://pypi.example.com/simple"].
  • The two existing pip_compile_index_urls examples are unchanged.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass. Not run locally: I had no Ruby 3.x environment for dependabot-core. Relying on CI; I syntax-checked the four files.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality. Specs added in both ecosystems, not run locally (see above).
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

🤖 Generated with Claude Code

pip_compile_index_urls passed every credential of the job through
AuthedUrlBuilder.authed_url. A credential without an index-url, such as the
github.com git_source credential, gives "", so the list became [nil, ""].
CompileFileUpdater#package_hashes_for passes a truthy "" to the hash helper,
and hashin then requests "/pypi/<name>/json", which fails with
"ValueError: unknown url type". The dependency is left out of the update.

It shows only when a package's new version has fewer hashes than the old one
(update_hashes_if_required), which is why only some packages fail.

Fixes dependabot#12260

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikgerling

Copy link
Copy Markdown
Author

Reopened: this was closed by accident, by a closing keyword in a pull request of mine elsewhere that only linked here. The change is unchanged and still ready for review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression tests call private methods via send, contrary to testing guidelines, and leave the public handoff of filtered index URLs to the pip-compile and uv updater constructors untested.

1 open issue
What changed in this PR

This PR addresses #12260 by filtering empty credential-derived index URLs before hash lookups in the Python and uv ecosystems, preventing malformed /pypi/<name>/json requests.

Changes:

  • Remove empty URLs while preserving the default-index sentinel and existing replaces-base behavior.
  • Add regression examples using mixed Git and Python index credentials in both ecosystems.
File Description
uv/​spec/​dependabot/​uv/​file_updater_spec.rb Adds mixed-credential regression coverage for uv.
uv/​lib/​dependabot/​uv/​file_updater.rb Filters empty index URLs before uv hash lookups.
python/​spec/​dependabot/​python/​file_updater_spec.rb Adds mixed-credential regression coverage for Python.
python/​lib/​dependabot/​python/​file_updater.rb Applies the same empty-URL filtering to Python.

Review effort: Balanced

end

it "leaves it out, so no hash lookup gets an empty index URL" do
expect(instance.send(:pip_compile_index_urls)).to eq([nil, "https://pypi.example.com/simple"])

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unknown url type error

3 participants