Skip to content

fix: allow unsetting unknown config keys#6106

Open
lisiqi1983 wants to merge 5 commits into
prefix-dev:mainfrom
lisiqi1983:codex/allow-unset-unknown-config-key
Open

fix: allow unsetting unknown config keys#6106
lisiqi1983 wants to merge 5 commits into
prefix-dev:mainfrom
lisiqi1983:codex/allow-unset-unknown-config-key

Conversation

@lisiqi1983
Copy link
Copy Markdown

@lisiqi1983 lisiqi1983 commented May 13, 2026

Description

Fixes #5672.

pixi config unset returned an unknown-key error when the requested key was no longer part of the config schema. That made it hard to clean up stale config values such as the removed repodata-config.disable-jlap entry.

This keeps setting unknown keys strict, but allows unset operations (value == None) to continue for unknown or deprecated keys. For unsupported/stale keys that exist in the target TOML file, the CLI now removes only the requested dotted key from the TOML document instead of serializing the typed config and dropping every unknown field.

Before, trying to remove a stale key such as repodata-config.disable-jlap failed before saving. After this change, the unset operation is accepted and the file is rewritten without that stale key while preserving unrelated unknown keys and supported entries such as repodata-config.disable-bzip2.

How Has This Been Tested?

  • cargo fmt --check -p pixi_config -p pixi_cli
  • cargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_key
  • cargo test -p pixi_config
  • cargo check -p pixi_cli
  • git diff --check

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: OpenAI Codex

Prompt: Fix the pixi config unset stale-key cleanup issue and address maintainer feedback by proving the stale key is removed without removing other unknown keys from the saved config file.

Checklist:

  • I have performed a self-review of my own code
  • I have added sufficient tests to cover my changes.

@lisiqi1983 lisiqi1983 changed the title Allow unsetting unknown config keys fix: allow unsetting unknown config keys May 13, 2026
@baszalmstra
Copy link
Copy Markdown
Contributor

Thanks! But can you follow the PR template from the repository?

@baszalmstra
Copy link
Copy Markdown
Contributor

Reading the PR carefully it looks like it just doesnt error, but does it also actually unset the key?

@lisiqi1983
Copy link
Copy Markdown
Author

lisiqi1983 commented May 13, 2026

Thanks for the review. I updated the PR description to follow the repository template.

It does actually remove the key after saving. I added test_unset_unknown_key_rewrites_config_without_stale_key to make that explicit: the test writes a config file containing both stale repodata-config.disable-jlap and supported repodata-config.disable-bzip2, loads it with Config::from_path, runs config.set("repodata-config.disable-jlap", None), saves back to the same path, and asserts the saved file no longer contains disable-jlap while still preserving disable-bzip2.

Latest verification:

  • cargo fmt --check -p pixi_config
  • cargo test -p pixi_config test_unset_unknown_key_rewrites_config_without_stale_key
  • cargo test -p pixi_config
  • git diff --check

Comment thread crates/pixi_config/src/lib.rs Outdated
}

#[test]
fn test_unset_unknown_key_rewrites_config_without_stale_key() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you try this with a file that contains multiple nonsense keys, you call set to remove one of them and then have a insta snapshot that shows that only that particular key is removed?

Im asking because I could not find the logic that actually removes a single value from the toml document, so Im not convinced that that actually works.

Copy link
Copy Markdown
Author

@lisiqi1983 lisiqi1983 May 13, 2026

Choose a reason for hiding this comment

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

Good point. The previous version proved that the stale key disappeared after serialization, but it did not preserve other unknown keys.

I changed the unset path for unsupported/stale keys to edit the TOML document directly, removing only the requested dotted key and preserving the rest of the document. I also updated the test to use multiple unknown keys and an inline insta::assert_snapshot!; it calls Config::set("repodata-config.disable-jlap", None) and the snapshot shows that only disable-jlap is removed while kept-unknown, also-kept, and disable-bzip2 remain.

Verified with:

  • cargo fmt --check -p pixi_config -p pixi_cli
  • cargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_key
  • cargo test -p pixi_config
  • cargo check -p pixi_cli
  • git diff --check

Comment thread crates/pixi_cli/src/config.rs Outdated
AlterMode::Set | AlterMode::Unset => config.set(key, value)?,
AlterMode::Set => config.set(key, value)?,
AlterMode::Unset => {
config.set(key, None)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will still error out if the key is unknown ...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right. I changed the branch so unsupported/stale keys no longer go through Config::set before the TOML edit path.

The unset flow now uses typed Config::set(key, None) only for supported keys, and otherwise edits the target TOML document directly with remove_key_from_toml, preserving other unknown keys.

Verified with:

  • cargo fmt --check -p pixi_cli -p pixi_config
  • cargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_key
  • cargo check -p pixi_cli
  • git diff --check

Copy link
Copy Markdown
Author

Pushed a tiny follow-up commit to keep the success output consistent: the early-return unset path now prints the same ✅ Updated config at … line as the normal config.save(...) path.

Local re-validation:

  • cargo fmt --check -p pixi_cli -p pixi_config
  • cargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_key
  • cargo check -p pixi_cli

CI is rerunning on head 3935a28160dc550107245d7a5d304dc9bfb56ce8.

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.

pixi config unset should not error on unknown keys

2 participants