python-poetry/poetry · error · ValueError
FileCache.hash_type is unknown value: '{self.hash_type}'.
Error message
FileCache.hash_type is unknown value: '{self.hash_type}'. What it means
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.
Source
Thrown at src/poetry/utils/cache.py:88
"""
return self.expires is not None and time.time() >= self.expires
@dataclasses.dataclass(frozen=True)
class FileCache(Generic[T]):
"""
Cachy-compatible minimal file cache. Stores subsequent data in a JSON format.
:param path: The path that the cache starts at.
:param hash_type: The hash to use for encoding keys/building directories.
"""
path: Path
hash_type: str = "sha256"
def __post_init__(self) -> None:
if self.hash_type not in _HASHES:
raise ValueError(
f"FileCache.hash_type is unknown value: '{self.hash_type}'."
)
def get(self, key: str) -> T | None:
return self._get_payload(key)
def has(self, key: str) -> bool:
"""
Determine if a file exists and has not expired in the cache.
:param key: The cache key
:returns: True if the key exists in the cache
"""
return self.get(key) is not None
def put(self, key: str, value: Any, minutes: int | None = None) -> None:
"""
Store an item in the cache.
View on GitHub (pinned to 92b74dcfe3)
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.
Example fix
// before cache = FileCache(path=cache_dir, hash_type="sha512") // after cache = FileCache(path=cache_dir, hash_type="sha256")
Defensive patterns
Strategy: type-guard
Type guard
SUPPORTED_HASH_TYPES = {"md5", "sha1", "sha256"}
def is_valid_hash_type(value: str) -> bool:
return isinstance(value, str) and value in SUPPORTED_HASH_TYPES Try / catch
try:
cache = FileCache(path=cache_dir, hash_type=hash_type)
except ValueError as e:
if "unknown value" in str(e):
hash_type = "sha256"
cache = FileCache(path=cache_dir, hash_type=hash_type)
raise Prevention
- 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.
When it happens
Trigger: Constructing FileCache(path, hash_type='sha512') or any value outside {md5, sha1, sha256}; passing a typo'd algorithm name programmatically.
Common situations: Programmatic misuse of the FileCache dataclass; a config typo feeding an unsupported hash algorithm; copy-pasting code expecting sha512 support.
Related errors
- Setting {self.argument('key')} does not exist
- You can only pass one value.
- "{value}" is an invalid value for {key}
- Hash for {package} from archive {archive.name} not found in
- The name [pypi] is reserved for repositories
AI-assisted analysis of python-poetry/poetry@92b74dcfe3 (2026-08-04).
Data as JSON: /data/errors/03af7b913cb55dcc.json.
Report an issue: GitHub.