Erroneous version change when updating overriden package version

Open
#8,480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
tooling

Research direction

Reproduce the issue using the patch-buggy-version-change branch, then work from artifact/Cargo.toml and the generated artifact/Cargo.lock. Run cargo +nightly update -p serde_json and inspect the lockfile diff. Done means updating serde_json does not change the serde version selected for ipnetwork.

Written by the indexing model from the issue text.

Description

A-patch C-bug S-triage

In a crate graph with:

  • two different versions of the same crate A1 & A2
  • a dependency B with a version specification that allows both versions A1 and A2, currently locked at A2
  • a dependency C that has a dependency on A2

If I add a patch override for dependency C which changes the version of C and use cargo update -p C, the version that B depends on gets changed to A1.

You can see it in action in https://github.com/jethrogb/cargo/tree/patch-buggy-version-change

# Clone test repository
git clone --single-branch https://github.com/jethrogb/cargo -b patch-buggy-version-change
cd cargo/artifact

# Introduce [patch.crates-io.serde_json]
sed -i '15s/#//' Cargo.toml

# Update serde_json
cargo +nightly update -p serde_json

# Observe serde version change in ipnetwork
git diff Cargo.lock

You can see this changes the version of serde that ipnetwork depends on:

diff --git a/artifact/Cargo.lock b/artifact/Cargo.lock
index 6be3a00..b2c5754 100644
--- a/artifact/Cargo.lock
+++ b/artifact/Cargo.lock
@@ -15,22 +15,10 @@ version = "0.16.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b8eca9f51da27bc908ef3dd85c21e1bbba794edaf94d7841e37356275b82d31e"
 dependencies = [
- "serde 1.0.114",
+ "serde 0.8.23",
 ]

I'm using cargo update -p to update only a specific package version. This should leave the dependency of ipnetwork unchanged.

Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/cargo

All issues in rust-lang/cargo

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.