Skip to content

uv lock --upgrade writes a dead edge (python_version < '0') that a lock-guided uv lock drops, so uv.lock flips #23410

Backlog

Description

@bitranox

When a lock forks on the Python version, uv lock --upgrade (or locking with no uv.lock yet) writes a dependency edge whose marker can never be true:

{ name = "beta", version = "2.0", source = { ... }, marker = "python_version < '0'" }

A plain uv lock that has to re-resolve against the existing lock, for example after the project's own version changed, writes the same resolution without that edge. Each form accepts the other's lockfile (--dry-run reports no changes), so a project whose tooling runs both gets the same one-line diff in uv.lock back and forth. We hit it on every release of a project where the release step re-locked with plain uv lock and the test step with uv lock --upgrade; in that project the dead edge is build's dependency on importlib-metadata (python_full_version < '3.10.2') inside the >= 3.11 fork.

Seen with uv 0.13.0 and 0.13.10 on x86_64 Linux.

Reproduction (offline, generated wheels)

alpha 1.0  Requires-Dist: beta; python_full_version < '3.10.2'
gamma 1.0  Requires-Dist: beta>=2; python_version >= '3.11'
beta  1.0
beta  2.0  Requires-Python: >=3.11
[project]
name = "demo"
version = "1.0.0"
requires-python = ">=3.10"
dependencies = ["alpha", "gamma"]

[tool.uv]
find-links = ["<dir with the wheels>"]
no-index = true
  1. uv lock with no lockfile: alpha's dependencies include beta 2.0 with marker = "python_version < '0'".
  2. Set version = "1.0.1", run uv lock: the edge is gone.
  3. uv lock --upgrade: the edge is back.

The lock forks at 3.11. In the >= 3.11 fork alpha's python_full_version < '3.10.2' requirement can't hold, and the from-scratch path keeps the edge with the marker simplified to false instead of dropping it.

Expected

The same resolution gives the same lockfile whichever path produced it. I'd expect the edge to be left out, as the lock-guided path already does.

Script that builds the wheels and runs the three steps (python3 repro.py <empty dir>)
"""Probe: do tiny local wheels reproduce uv's dead `python_version < '0'` edge?

Usage: python3 fixture_probe.py <workdir>
Prints the dead-edge count after a fresh lock, after a version change + plain lock, and after
--upgrade, so the bump/gate flip is visible.
"""

from __future__ import annotations

import subprocess
import sys
import zipfile
from pathlib import Path


def wheel(dist: Path, name: str, version: str, requires: list[str], requires_python: str | None = None) -> None:
    tag = f"{name}-{version}"
    meta = [f"Metadata-Version: 2.1", f"Name: {name}", f"Version: {version}"]
    if requires_python:
        meta.append(f"Requires-Python: {requires_python}")
    meta += [f"Requires-Dist: {r}" for r in requires]
    files = {
        f"{name}/__init__.py": "",
        f"{tag}.dist-info/METADATA": "\n".join(meta) + "\n",
        f"{tag}.dist-info/WHEEL": "Wheel-Version: 1.0\nGenerator: probe\nRoot-Is-Purelib: true\nTag: py3-none-any\n",
    }
    record = "".join(f"{p},,\n" for p in files) + f"{tag}.dist-info/RECORD,,\n"
    with zipfile.ZipFile(dist / f"{tag}-py3-none-any.whl", "w") as zf:
        for path, text in files.items():
            zf.writestr(path, text)
        zf.writestr(f"{tag}.dist-info/RECORD", record)


def project(root: Path, version: str, links: Path) -> None:
    (root / "pyproject.toml").write_text(
        "[project]\n"
        'name = "demo"\n'
        f'version = "{version}"\n'
        'requires-python = ">=3.10"\n'
        'dependencies = ["alpha", "gamma"]\n'
        "[tool.uv]\n"
        f'find-links = ["{links.as_posix()}"]\n'
        "no-index = true\n",
        encoding="utf-8",
    )


def dead(root: Path) -> int:
    return (root / "uv.lock").read_text(encoding="utf-8").count("python_version < '0'")


def lock(root: Path, *args: str) -> None:
    subprocess.run(["uv", "lock", "-q", *args], cwd=root, check=True)


def main() -> None:
    work = Path(sys.argv[1])
    dist = work / "dist"
    dist.mkdir(parents=True)
    wheel(dist, "alpha", "1.0", ["beta; python_full_version < '3.10.2'"])
    wheel(dist, "gamma", "1.0", ["beta>=2; python_version >= '3.11'"])
    wheel(dist, "beta", "1.0", [])
    wheel(dist, "beta", "2.0", [], requires_python=">=3.11")
    root = work / "proj"
    root.mkdir()
    project(root, "1.0.0", dist)
    lock(root)
    print("fresh lock:", dead(root))
    project(root, "1.0.1", dist)
    lock(root)
    print("version change + plain lock:", dead(root))
    lock(root, "--upgrade")
    print("then --upgrade:", dead(root))
    print((root / "uv.lock").read_text(encoding="utf-8"))


if __name__ == "__main__":
    main()

Output with uv 0.13.10:

fresh lock: 1
version change + plain lock: 0
then --upgrade: 1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions