Skip to content

Fix UV_NO_CACHE=false not overriding no-cache=true in config file - #19895

Closed
tdhopper wants to merge 11 commits into
astral-sh:mainfrom
tdhopper:fix/no-cache-env-var-precedence
Closed

tdhopper wants to merge 11 commits into
astral-sh:mainfrom
tdhopper:fix/no-cache-env-var-precedence

Conversation

@tdhopper

@tdhopper tdhopper commented Jun 17, 2026 •

Copy link
Copy Markdown

Summary

CacheSettings::resolve() used || to combine the CLI/env var and config file values for no-cache, so if the config file set no-cache = true, UV_NO_CACHE=false had no effect (false || true == true).

The fix uses the same flag pair pattern as --offline/--no-offline:

  • Added a hidden --cache flag with overrides_with, paired with --no-cache
  • Removed env = UV_NO_CACHE from the clap attribute — the env var is now read manually via env_no_cache() using parse_boolish_environment_variable, matching how UV_OFFLINE is handled
  • resolve() uses flag(cache, no_cache, "cache").map(|cache| !cache).combine(env_no_cache()).combine(workspace).unwrap_or(false)
  • Added [env: UV_NO_CACHE=] to the doc comment so it still appears in --help
  • Pre-resolution cache paths (discovery_cache in lib.rs, TryFrom<CacheArgs> in uv-dev) also check UV_NO_CACHE

Test plan

  • Unit tests: --cache flag overrides config, --no-cache flag overrides config
  • cargo clippy clean on uv-cache, uv, uv-dev
  • cargo test -- help:: (14 tests pass)
  • cargo test -- upgrade::upgrade_help passes
  • cargo test -- show_settings::resolve_uv_toml passes
  • Manual verification: uv --no-cache pip --help, uv --no-cache --version, uv --cache --version, uv -n pip --help, UV_NO_CACHE=false uv --version all work
  • Manual verification of the actual fix: with no-cache = true in uv.toml, UV_NO_CACHE=false correctly resolves no_cache: false

@woodruffw

Copy link
Copy Markdown
Member

#13953 appears to be an unrelated (merged) PR, not a bug report. Did you mean to link something else?

@tdhopper
tdhopper force-pushed the fix/no-cache-env-var-precedence branch from f1e017f to 8c60746 Compare June 17, 2026 16:29
Comment thread crates/uv-cache/src/cli.rs Resolved
CacheSettings::resolve() used || to combine the env var and config file
values for no-cache. This meant if the config file set no-cache = true,
the env var could only agree — UV_NO_CACHE=false had no effect.

Changed CacheArgs.no_cache from bool to Option<bool> so we can
distinguish 'explicitly set to false' from 'not set'. The resolve()
method now uses .combine() (same pattern as offline, native-tls, etc.)
which gives the env var/CLI arg precedence when set, falling back to the
config file value otherwise.

Fixes the precedence order documented at:
https://docs.astral.sh/uv/concepts/configuration-files/
@tdhopper
tdhopper force-pushed the fix/no-cache-env-var-precedence branch from 8c60746 to b7b3674 Compare June 17, 2026 17:17
tdhopper added 7 commits June 17, 2026 13:33
Replace the Option<bool> + BoolishValueParser approach on --no-cache with
the idiomatic flag pair pattern used throughout the codebase (e.g.
--offline/--no-offline).

Changes:
- Revert --no-cache to a plain bool flag, add hidden --cache counterpart
  with overrides_with for mutual exclusion
- Remove env = EnvVars::UV_NO_CACHE from the clap attribute; handle the
  env var manually in CacheSettings::resolve() via new env_no_cache()
  helper that uses parse_boolish_environment_variable
- Resolution chain: flag(no_cache, cache) > UV_NO_CACHE env var > config
  file > default (false)
- Update unit tests to use the new bool/bool field layout
- Update help text snapshots (no more [=<NO_CACHE>], [env:], [possible
  values:])
- Fix flag() semantic inversion: use flag(cache, no_cache, "cache") with
  .map(|cache| !cache) so the error message correctly says --cache and
  --no-cache, matching the convention of all other flag pairs.

- Fix UV_NO_CACHE being ignored in pre-resolution paths: the discovery
  cache in lib.rs and TryFrom<CacheArgs> in uv-dev now also check the
  UV_NO_CACHE env var, not just the CLI flag.

- Add [env: UV_NO_CACHE=] to the doc comment so it appears in help text,
  matching the pattern used by --offline [env: UV_OFFLINE=].

- Remove flaky env-var-dependent unit tests (env::set_var is unsafe and
  not thread-safe with parallel test execution). Keep deterministic flag
  + config tests. Env var behavior is covered by integration tests.

- Restore help.rs and upgrade.rs snapshots to match upstream format.
All three call sites that resolve no_cache (CacheSettings::resolve,
TryFrom<CacheArgs>, and discovery_cache in lib.rs) now share the same
flag pair + env var logic via CacheArgs::resolved_no_cache().

Previously, TryFrom and discovery_cache ignored the --cache flag and
silently swallowed invalid UV_NO_CACHE values. Now all paths respect
both flags and produce consistent parse errors.
@astral-sh-bot

astral-sh-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the latest main baseline.

  • Added tests: 2
  • Removed tests: 1
  • Changed suites: 2
uv: +2 / -0

Added:

  • uv::settings::tests::cache_settings_cache_flag_overrides_config
  • uv::settings::tests::cache_settings_no_cache_flag_with_config_false

Removed: none

uv::project: +0 / -1

Added: none

Removed:

  • uv::project::tree::non_project_group_selection_with_extras

tdhopper added 3 commits June 18, 2026 10:19
…n test

- Add no_cache EnvFlag to EnvironmentOptions, matching the UV_OFFLINE pattern
- Pass EnvironmentOptions to CacheSettings::resolve() (1 caller updated)
- Remove standalone env_no_cache() helper
- Fix broken cross-crate doc link in resolved_no_cache()
- Fix exit(2) -> exit(1) to match parse_failure convention
- Add integration test proving UV_NO_CACHE=false overrides no-cache=true in config
@tdhopper
tdhopper requested a review from zanieb June 18, 2026 15:27
@tdhopper

Copy link
Copy Markdown
Author

#13953 appears to be an unrelated (merged) PR, not a bug report. Did you mean to link something else?

🙈 Claude slop, sorry...

@tdhopper

Copy link
Copy Markdown
Author

@zanieb I'd love to get eyes on this again when you have time, thanks!

@tdhopper tdhopper closed this Jul 12, 2026
zaniebot pushed a commit to astral-sh/uv-dev that referenced this pull request Oct 7, 2026
Exercise the configuration override reported in astral-sh#19895, including explicit CLI and opposite-environment controls.
zaniebot pushed a commit to astral-sh/uv-dev that referenced this pull request Oct 7, 2026
Retain the environment value separately so it can override no-cache in configuration, while the existing command-line flag remains authoritative. This narrows the precedence repair proposed by Tim Hopper in astral-sh#19895 without adding a new flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants