{"record":{"id":"80d598720b9a7643","repo":"pypa/pip","slug":"got-invalid-value-for-load-only-should-be-one-of","errorCode":null,"errorMessage":"Got invalid value for load_only - should be one of {}","messagePattern":"Got invalid value for load_only - should be one of (.+?)","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/configuration.py","lineNumber":106,"sourceCode":"class Configuration:\n    \"\"\"Handles management of configuration.\n\n    Provides an interface to accessing and managing configuration files.\n\n    This class converts provides an API that takes \"section.key-name\" style\n    keys and stores the value associated with it as \"key-name\" under the\n    section \"section\".\n\n    This allows for a clean interface wherein the both the section and the\n    key-name are preserved in an easy to manage form in the configuration files\n    and the data stored is also nice.\n    \"\"\"\n\n    def __init__(self, isolated: bool, load_only: Kind | None = None) -> None:\n        super().__init__()\n\n        if load_only is not None and load_only not in VALID_LOAD_ONLY:\n            raise ConfigurationError(\n                \"Got invalid value for load_only - should be one of {}\".format(\n                    \", \".join(map(repr, VALID_LOAD_ONLY))\n                )\n            )\n        self.isolated = isolated\n        self.load_only = load_only\n\n        # Because we keep track of where we got the data from\n        self._parsers: dict[Kind, list[tuple[str, RawConfigParser]]] = {\n            variant: [] for variant in OVERRIDE_ORDER\n        }\n        self._config: dict[Kind, dict[str, dict[str, Any]]] = {\n            variant: {} for variant in OVERRIDE_ORDER\n        }\n        self._modified_parsers: list[tuple[str, RawConfigParser]] = []\n\n    def load(self) -> None:\n        \"\"\"Loads configuration from configuration files and environment\"\"\"","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/configuration.py#L88-L124","documentation":"Raised by Configuration.__init__ when the load_only argument is not None and is not one of the three valid kinds: 'user', 'global', or 'site'. load_only restricts which configuration layer pip reads/writes, so an unrecognized value would make behavior undefined. This is an internal/programmatic error — the CLI maps --user/--global/--site to these strings, so end users rarely see it directly.","triggerScenarios":"Instantiating Configuration(isolated=False, load_only='something') directly with an invalid string; a bug or monkey-patch that passes an unexpected load_only value; a typo in code that wraps pip's configuration layer.","commonSituations":"Third-party tools that embed pip and construct a Configuration object with a wrong constant; test harnesses passing arbitrary strings; version skew where a vendored enum value changed.","solutions":["Pass one of the valid load_only values: 'user', 'global', or 'site' (the pip._internal.configuration.kinds constants).","If you do not need to restrict to a single layer, pass load_only=None.","If calling via the CLI, use --user / --global / --site which map correctly internally."],"exampleFix":"# before\nfrom pip._internal.configuration import Configuration\ncfg = Configuration(isolated=False, load_only='env')\n# after\nfrom pip._internal.configuration import Configuration, kinds\ncfg = Configuration(isolated=False, load_only=kinds.GLOBAL)","handlingStrategy":"validation","validationCode":"VALID_LOAD_ONLY = {'user', 'global', 'site'}\n\ndef make_configuration(isolated: bool, load_only: str | None):\n    if load_only is not None and load_only not in VALID_LOAD_ONLY:\n        raise ValueError(f'load_only must be one of {VALID_LOAD_ONLY} or None, got {load_only!r}')\n    from pip._internal.configuration import Configuration\n    return Configuration(isolated=isolated, load_only=load_only)\n","typeGuard":"def is_valid_load_only(value: str | None) -> bool:\n    return value is None or value in {'user', 'global', 'site'}\n","tryCatchPattern":null,"preventionTips":["Use the kinds constants from pip._internal.configuration instead of string literals.","Prefer the CLI flags --user/--global/--site over constructing Configuration directly."],"tags":["pip","config","configuration","internal","validation"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}