fix: allow unsetting unknown config keys#6106
Conversation
|
Thanks! But can you follow the PR template from the repository? |
|
Reading the PR carefully it looks like it just doesnt error, but does it also actually unset the key? |
|
Thanks for the review. I updated the PR description to follow the repository template. It does actually remove the key after saving. I added Latest verification:
|
| } | ||
|
|
||
| #[test] | ||
| fn test_unset_unknown_key_rewrites_config_without_stale_key() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_clicargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_keycargo test -p pixi_configcargo check -p pixi_cligit diff --check
| AlterMode::Set | AlterMode::Unset => config.set(key, value)?, | ||
| AlterMode::Set => config.set(key, value)?, | ||
| AlterMode::Unset => { | ||
| config.set(key, None)?; |
There was a problem hiding this comment.
This will still error out if the key is unknown ...
There was a problem hiding this comment.
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_configcargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_keycargo check -p pixi_cligit diff --check
|
Pushed a tiny follow-up commit to keep the success output consistent: the early-return Local re-validation:
CI is rerunning on head |
Description
Fixes #5672.
pixi config unsetreturned 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 removedrepodata-config.disable-jlapentry.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-jlapfailed 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 asrepodata-config.disable-bzip2.How Has This Been Tested?
cargo fmt --check -p pixi_config -p pixi_clicargo test -p pixi_config test_unset_unknown_key_removes_only_requested_toml_keycargo test -p pixi_configcargo check -p pixi_cligit diff --checkAI Disclosure
Tools: OpenAI Codex
Prompt: Fix the
pixi config unsetstale-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: