{"id":"c852e92d441006aa","repo":"python-poetry/poetry","slug":"value-is-an-invalid-value-for-key","errorCode":null,"errorMessage":"\"{value}\" is an invalid value for {key}","messagePattern":"\"(.+?)\" is an invalid value for (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/console/commands/config.py","lineNumber":383,"sourceCode":"            return 0\n\n        raise ValueError(f\"Setting {self.argument('key')} does not exist\")\n\n    def _handle_single_value(\n        self,\n        source: ConfigSource,\n        key: str,\n        callbacks: tuple[Any, Any],\n        values: list[Any],\n    ) -> int:\n        validator, normalizer = callbacks\n\n        if len(values) > 1:\n            raise RuntimeError(\"You can only pass one value.\")\n\n        value = values[0]\n        if not validator(value):\n            raise RuntimeError(f'\"{value}\" is an invalid value for {key}')\n\n        source.add_property(key, normalizer(value))\n\n        return 0\n\n    def _list_configuration(\n        self, config: dict[str, Any], raw: dict[str, Any], k: str = \"\"\n    ) -> None:\n        orig_k = k\n        for key, value in sorted(config.items()):\n            if k + key in self.LIST_PROHIBITED_SETTINGS:\n                continue\n\n            raw_val = raw.get(key)\n\n            if isinstance(value, dict):\n                k += f\"{key}.\"\n                raw_val = cast(\"dict[str, Any]\", raw_val)","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/console/commands/config.py#L365-L401","documentation":"RuntimeError from `_handle_single_value` (config.py:382-383) when the validator callback returns False. Each setting has a `(validator, normalizer)` pair; e.g. `virtualenvs.create` requires a boolean, `requests.max-retries` requires `int(val) >= 0`, `installer.max-workers` requires `int(val) > 0`.","triggerScenarios":"Passing `maybe` to a boolean setting; a negative integer to `requests.max-retries`; zero to `installer.max-workers`; a non-integer to a numeric key.","commonSituations":"Misremembering the expected type; passing `yes`/`no`/`on`/`off` when only strict booleans are accepted; negative retry counts.","solutions":["Match the validator: use `true`/`false` for booleans, a positive int for `installer.max-workers`, a non-negative int for `requests.max-retries`.","Inspect the validator in `unique_config_values` (config.py:78-101) to confirm accepted input.","Use `poetry config --list` to see current normalized values and mirror their format."],"exampleFix":"# before\npoetry config requests.max-retries -1\n# after\npoetry config requests.max-retries 5","handlingStrategy":"type-guard","validationCode":"from poetry.config.config import boolean_validator\nvalue = \"true\"\nif not boolean_validator(value):\n    raise SystemExit(f\"{value} is not a boolean\")\n# for numeric keys:\n# assert int(value) > 0 for installer.max-workers","typeGuard":"def fits_setting(key: str, value: str) -> bool:\n    from poetry.console.commands.config import ConfigCommand\n    specs = ConfigCommand().unique_config_values\n    if key not in specs:\n        return True  # unknown key handled elsewhere\n    validator, _ = specs[key]\n    try:\n        return bool(validator(value))\n    except Exception:\n        return False","tryCatchPattern":null,"preventionTips":["Look up the validator in `unique_config_values` before setting.","Use `true`/`false` for booleans, integers for numeric settings.","Mirror the normalized form shown by `poetry config --list`."],"tags":["config","validation","type-coercion"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}