{"id":"03af7b913cb55dcc","repo":"python-poetry/poetry","slug":"filecache-hash-type-is-unknown-value-self-hash","errorCode":null,"errorMessage":"FileCache.hash_type is unknown value: '{self.hash_type}'.","messagePattern":"FileCache\\.hash_type is unknown value: '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/cache.py","lineNumber":88,"sourceCode":"        \"\"\"\n        return self.expires is not None and time.time() >= self.expires\n\n\n@dataclasses.dataclass(frozen=True)\nclass FileCache(Generic[T]):\n    \"\"\"\n    Cachy-compatible minimal file cache. Stores subsequent data in a JSON format.\n\n    :param path: The path that the cache starts at.\n    :param hash_type: The hash to use for encoding keys/building directories.\n    \"\"\"\n\n    path: Path\n    hash_type: str = \"sha256\"\n\n    def __post_init__(self) -> None:\n        if self.hash_type not in _HASHES:\n            raise ValueError(\n                f\"FileCache.hash_type is unknown value: '{self.hash_type}'.\"\n            )\n\n    def get(self, key: str) -> T | None:\n        return self._get_payload(key)\n\n    def has(self, key: str) -> bool:\n        \"\"\"\n        Determine if a file exists and has not expired in the cache.\n        :param key: The cache key\n        :returns: True if the key exists in the cache\n        \"\"\"\n        return self.get(key) is not None\n\n    def put(self, key: str, value: Any, minutes: int | None = None) -> None:\n        \"\"\"\n        Store an item in the cache.\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/cache.py#L70-L106","documentation":"FileCache.__post_init__ validates that hash_type is one of the supported algorithms {md5, sha1, sha256} (cache.py:50-54, 86-90) and raises ValueError otherwise. The hash_type drives cache-key hashing and directory layout, so an unsupported value would silently corrupt cache behavior; the check fails fast instead.","triggerScenarios":"Constructing FileCache(path, hash_type='sha512') or any value outside {md5, sha1, sha256}; passing a typo'd algorithm name programmatically.","commonSituations":"Programmatic misuse of the FileCache dataclass; a config typo feeding an unsupported hash algorithm; copy-pasting code expecting sha512 support.","solutions":["Use one of the supported values: 'md5', 'sha1', or 'sha256' (default 'sha256').","If you need a stronger hash, note FileCache only supports these three and file hashes elsewhere are handled by the repository layer.","Validate the value against the allowed set before constructing FileCache."],"exampleFix":"// before\ncache = FileCache(path=cache_dir, hash_type=\"sha512\")\n// after\ncache = FileCache(path=cache_dir, hash_type=\"sha256\")","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"SUPPORTED_HASH_TYPES = {\"md5\", \"sha1\", \"sha256\"}\n\ndef is_valid_hash_type(value: str) -> bool:\n    return isinstance(value, str) and value in SUPPORTED_HASH_TYPES","tryCatchPattern":"try:\n    cache = FileCache(path=cache_dir, hash_type=hash_type)\nexcept ValueError as e:\n    if \"unknown value\" in str(e):\n        hash_type = \"sha256\"\n        cache = FileCache(path=cache_dir, hash_type=hash_type)\n    raise","preventionTips":["Default to 'sha256' when constructing FileCache.","Validate hash_type against {md5, sha1, sha256} before constructing.","Do not source hash_type from untrusted config without validation."],"tags":["cache","config","validation","hash"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}