Skip to content

Fix invalid config values soft-locking pip#14011

Open
sepehr-rs wants to merge 19 commits into
pypa:mainfrom
sepehr-rs:fix-use-feature
Open

Fix invalid config values soft-locking pip#14011
sepehr-rs wants to merge 19 commits into
pypa:mainfrom
sepehr-rs:fix-use-feature

Conversation

@sepehr-rs

Copy link
Copy Markdown
Member

Fixes #8671. Warn and skip invalid use-feature config values instead of crashing.
I also had to keep track of the invalid variables because check_default was called a lot, creating many duplicate logging messages.
Happy to adjust the approach if maintainers have a different preference.

@ichard26 ichard26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm confused, the PR claims to only prevent invalid use-feature values from stopping pip to function, but this seems to ignore all invalid configuration keys?

@sepehr-rs

Copy link
Copy Markdown
Member Author

You're right. While the issue was reported for use-feature, the same underlying bug can be reproduced with use-deprecated, keyring-provider, exists-action, and other configuration options.

The PR title and news entry are too narrowly scoped given what the change actually does. I'll update them.

@sepehr-rs sepehr-rs changed the title Fix invalid use-feature value soft-locking pip Fix invalid config values soft-locking pip Jun 25, 2026
@ichard26

ichard26 commented Jul 1, 2026

Copy link
Copy Markdown
Member

I'm not sure if ignoring invalid values for all configuration options is a good idea. For example, if someone uses use-deprecated and then a future version of pip removes support for a deprecated feature, pip should fail loudly informing the user that this deprecated feature is gone. This has two benefits:

  • It doesn't lead to unpredictable failures when the invocation probably crashes, possibly after tens or hundreds of lines of output
  • If they don't actually need the deprecated feature anymore, they ought to remove the flag.

There are similar concerns with options like index-url, only-binary, and possibly others.

@sepehr-rs

Copy link
Copy Markdown
Member Author

pip should fail loudly informing the user that this deprecated feature is gone.

I see your point, and I agree that users should be clearly informed when they're relying on a feature that no longer exists. At the same time, I think preventing users from using pip entirely, especially with the current error message, can be frustrating for users.

I think there are two possible approaches:

  1. Fail with a clear, actionable error message that explains exactly what's wrong and how to fix it.
  2. Show an informative warning, ignore the invalid configuration value, and continue running pip. (This is close to the current approach I took, but with a better warning.)

I'd be interested to hear which approach you think is more reasonable.

@danielhollas

Copy link
Copy Markdown
Contributor

I think there are two possible approaches:

I'd say the third option is to (somehow) scope this PR down so that it only applies to the --use-feature flag, which is what the original issue asked for.

@sepehr-rs

Copy link
Copy Markdown
Member Author

I'd say the third option is to (somehow) scope this PR down so that it only applies to the --use-feature flag, which is what the original issue asked for.

That's a possible solution, but I don't think it addresses the root issue. Narrowing the scope avoids the immediate problem, but we'll probably just see another issue opened later when exists-action or use-deprecated ends up soft-locking pip for the same reason.

@danielhollas

Copy link
Copy Markdown
Contributor

The three options you mention are imo very much different and should be treated differently.

--exists-action seem to have a well-defined set of options so pip should error out if a wrong one is provided.

On the other hand, the list of possible options for -use-feature and -use-deprecated changes in different pip versions so it makes sense to be more lenient. Especially for use-feature, where the user is supposedly opting into a future feature so we should not punish them once the future finally arrives and the feature is stable.

@sepehr-rs

Copy link
Copy Markdown
Member Author

Especially for use-feature, where the user is supposedly opting into a future feature so we should not punish them once the future finally arrives and the feature is stable.

Good point. What do you think about taking a more balanced approach? We could warn and ignore invalid values for use-feature so users aren't punished when a feature becomes stable, while still raising an error for options like use-deprecated, exists-action, and other configuration values that are expected to remain valid."

@danielhollas

Copy link
Copy Markdown
Contributor

We could warn and ignore invalid values for use-feature so users aren't punished when a feature becomes stable, while still raising an error for options like use-deprecated, exists-action, and other configuration values that are expected to remain valid.

Yes, I think this would make sense.

@sepehr-rs

Copy link
Copy Markdown
Member Author

I updated the code to reflect the discussion we had. Pip now warns on invalid use-feature values but throws an error on other invalid config values.

@ichard26 ichard26 added this to the 26.2 milestone Jul 25, 2026
Comment thread src/pip/_internal/cli/parser.py Outdated
Comment thread news/8671.bugfix.rst Outdated
@sepehr-rs

sepehr-rs commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

Since pip becomes completely unusable when a configuration value (besides use-feature) is invalid, I added the configuration directory the invalid value came from to the error message. I think this makes the error clearer and more actionable. Let me know what you think.

Comment thread src/pip/_internal/cli/parser.py Outdated
Comment thread src/pip/_internal/cli/parser.py Outdated
Comment thread src/pip/_internal/cli/parser.py Outdated
@sepehr-rs

Copy link
Copy Markdown
Member Author

Thanks for the review!

I replaced the config file name with a link to the documentation to avoid ambiguity, and switched to self.error to make the error message more user-friendly. The only remaining issue is that optparse's error output is a bit odd:

[optparse.groups]Usage:[/]   
  pip <command> \[options]

Invalid value for configuration option 'use-deprecated': option use-deprecated: invalid choice: 'x' (choose from 'legacy-resolver', 'legacy-certs'). Check your pip configuration files for this value. See https://pip.pypa.io/en/stable/topics/configuration/#location for config file locations.

But I think that's outside the scope of this PR and would be better addressed separately.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid use-feature value breaks pip

3 participants