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

Avoid panic when re-locking with precise commit #5863

Merged
merged 2 commits into from
Aug 7, 2024
Merged

Conversation

charliermarsh
Copy link
Member

Summary

Very subtle bug. The scenario is as follows:

  • We resolve: elmer-circuitbuilder = { git = "https://github.com/ElmerCSC/elmer_circuitbuilder.git" }

  • The user then changes the request to: elmer-circuitbuilder = { git = "https://github.com/ElmerCSC/elmer_circuitbuilder.git", rev = "44d2f4b19d6837ea990c16f494bdf7543d57483d" }

  • When we go to re-lock, we note two facts:

    1. The "default branch" resolves to 44d2f4b19d6837ea990c16f494bdf7543d57483d.
    2. The metadata for 44d2f4b19d6837ea990c16f494bdf7543d57483d is (whatever we grab from the lockfile).
  • In the resolver, we then ask for the metadata for 44d2f4b19d6837ea990c16f494bdf7543d57483d. It's already in the cache, so we return it; thus, we never add the 44d2f4b19d6837ea990c16f494bdf7543d57483d -> 44d2f4b19d6837ea990c16f494bdf7543d57483d mapping to the Git resolver, because we never have to resolve it.

This would apply for any case in which a requested tag or branch was replaced by its precise SHA. Replacing with a different commit is fine.

It only applied to tool.uv.sources, and not PEP 508 URLs, because the underlying issue is that we aren't consistent about "automatically" extracting the precise commit from a Git reference.

Closes #5860.

pub fn new(repository: Url, reference: GitReference) -> Self {
/// Create a new [`GitUrl`] from a repository URL and a reference.
pub fn from_reference(repository: Url, reference: GitReference) -> Self {
let precise = reference.as_sha();
Copy link
Member Author

Choose a reason for hiding this comment

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

Main change: we now always extract precise if it's a Git reference.

@charliermarsh charliermarsh added bug Something isn't working preview Experimental behavior labels Aug 7, 2024
@charliermarsh charliermarsh merged commit e4ec6e4 into main Aug 7, 2024
57 checks passed
@charliermarsh charliermarsh deleted the charlie/lock-git branch August 7, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Precise commits raise panic when locking
1 participant