astral-sh/uv · error · anyhow::Error

Cannot use ` ` as an override file

Error message

Cannot use `{}` as an override file

What it means

Thrown in RequirementsSpecification::from_sources (crates/uv-requirements/src/specification.rs:440) when the overrides list contains a RequirementsSource::PylockToml variant. Overrides are requirements.txt-format pins applied to the resolution; a full lock file is neither parsed nor applied that way, so uv rejects the combination at assembly time (mirrors error 43 at the API level).

Solutions

  1. Drop the pylock.toml from the overrides list and supply overrides.txt-style pins instead
  2. Export the pins: `uv export --format requirements-txt -o overrides.txt`
  3. Reconsider the design — to install exactly the lock, use it as the requirements source, not an override

Example fix

# before (programmatic)
overrides: vec![RequirementsSource::PylockToml(lock.into())],
// after
overrides: vec![RequirementsSource::RequirementsTxt(ovr.into())],
Defensive patterns

Strategy: validation

Validate before calling

let bad = overrides.iter().any(|s| matches!(s, RequirementsSource::PylockToml(_)));
if bad {
    return Err(anyhow::anyhow!("refusing to assemble spec: pylock.toml is not an override source"));
}

Type guard

fn is_pylock_source(s: &RequirementsSource) -> bool {
    matches!(s, RequirementsSource::PylockToml(_))
}

Try / catch

match RequirementsSpecification::from_sources(/* .. */).await {
    Err(err) if err.to_string().contains("as an override file") => {
        // replace with an exported overrides.txt and reassemble
    }
    spec => spec?,
}

Prevention

When it happens

Trigger: Programmatic from_sources call with a PylockToml source inside the overrides Vec; an upstream flow that classified an --overrides path as a pylock source before reaching this constructor; only the first match is reported.

Common situations: Automation layering a corporate lock file as overrides on user requirements; wrapper tools assembling source lists from globs.

Related errors


AI-assisted analysis of astral-sh/uv@f1a42680ff (2026-08-16). Data as JSON: /api/errors/629d425bf7b3699e. Report an issue: GitHub.

Appendix: source

Thrown at crates/uv-requirements/src/specification.rs:440

            } else {
                None
            }
        }) {
            return Err(anyhow::anyhow!(
                "Cannot use `{}` as a constraint file",
                pylock_toml.user_display()
            ));
        }

        // Disallow `pylock.toml` files as overrides.
        if let Some(pylock_toml) = overrides.iter().find_map(|source| {
            if let RequirementsSource::PylockToml(path) = source {
                Some(path)
            } else {
                None
            }
        }) {
            return Err(anyhow::anyhow!(
                "Cannot use `{}` as an override file",
                pylock_toml.user_display()
            ));
        }

        // Disallow `pylock.toml` files as excludes.
        if let Some(pylock_toml) = excludes.iter().find_map(|source| {
            if let RequirementsSource::PylockToml(path) = source {
                Some(path)
            } else {
                None
            }
        }) {
            return Err(anyhow::anyhow!(
                "Cannot use `{}` as an exclude file",
                pylock_toml.user_display()
            ));
        }

View on GitHub (pinned to f1a42680ff)