{"id":"bb103c0abff14508","repo":"pypa/pip","slug":"no-such-key-orig-key","errorCode":null,"errorMessage":"No such key - {orig_key}","messagePattern":"No such key - (.+?)","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/configuration.py","lineNumber":157,"sourceCode":"        \"\"\"Returns key-value pairs like dict.items() representing the loaded\n        configuration\n        \"\"\"\n        return self._dictionary.items()\n\n    def get_value(self, key: str) -> Any:\n        \"\"\"Get a value from the configuration.\"\"\"\n        orig_key = key\n        key = _normalize_name(key)\n        try:\n            clean_config: dict[str, Any] = {}\n            for file_values in self._dictionary.values():\n                clean_config.update(file_values)\n            return clean_config[key]\n        except KeyError:\n            # disassembling triggers a more useful error message than simply\n            # \"No such key\" in the case that the key isn't in the form command.option\n            _disassemble_key(key)\n            raise ConfigurationError(f\"No such key - {orig_key}\")\n\n    def set_value(self, key: str, value: Any) -> None:\n        \"\"\"Modify a value in the configuration.\"\"\"\n        key = _normalize_name(key)\n        self._ensure_have_load_only()\n\n        assert self.load_only\n        fname, parser = self._get_parser_to_modify()\n\n        if parser is not None:\n            section, name = _disassemble_key(key)\n\n            # Modify the parser and the configuration\n            if not parser.has_section(section):\n                parser.add_section(section)\n            parser.set(section, name, value)\n\n        self._config[self.load_only].setdefault(fname, {})","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/configuration.py#L139-L175","documentation":"Raised as ConfigurationError in Configuration.get_value() at configuration.py:157 when the normalized key is not found in the merged configuration dictionary. Note _disassemble_key is called first (line 156), so this specific message only appears when the key HAS a dot (a dot-less key raises error [52] instead). The orig_key in the message is the un-normalized key the caller supplied.","triggerScenarios":"Calling Configuration.get_value('global.nonexistent') (or via 'pip config get global.nonexistent') when that key is absent from all loaded config variants. The KeyError at line 153 is caught and re-raised as this ConfigurationError.","commonSituations":"Querying a config key that was never set; typo in the key name; querying before Configuration.load() was called; expecting a default that pip does not actually store in config.","solutions":["Verify the key exists with 'pip config list' or 'pip config debug'.","Check spelling — keys are normalized (lowercase, dashes for underscores), so use the canonical form like 'global.index-url'.","Ensure Configuration.load() has been called before get_value().","If using get_value programmatically, catch ConfigurationError to handle missing keys gracefully."],"exampleFix":"# before\npip config get global.retries  # not set -> error\n# after\npip config set global.retries 5\npip config get global.retries","handlingStrategy":"validation","validationCode":"from pip._internal.configuration import Configuration\nfrom pip._internal.exceptions import ConfigurationError\n\ndef safe_get_value(cfg: Configuration, key: str, default=None):\n    cfg.load()\n    try:\n        return cfg.get_value(key)\n    except ConfigurationError:\n        return default\n\n# Usage\nval = safe_get_value(cfg, 'global.retries', default=5)","typeGuard":"from pip._internal.configuration import Configuration\n\ndef key_exists(cfg: Configuration, key: str) -> bool:\n    cfg.load()\n    try:\n        cfg.get_value(key)\n        return True\n    except Exception:\n        return False","tryCatchPattern":"from pip._internal.exceptions import ConfigurationError\ntry:\n    value = cfg.get_value('global.retries')\nexcept ConfigurationError as e:\n    if 'No such key' in str(e):\n        value = None  # treat as missing\n    else:\n        raise","preventionTips":["Call Configuration.load() before get_value().","Check 'pip config list' / 'pip config debug' for valid key names.","Catch ConfigurationError and provide a sensible default when a missing key is expected."],"tags":["pip","config","configuration","key-not-found","get"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}