{"record":{"id":"99ad020a559e49ff","repo":"pola-rs/polars","slug":"key-r-not-found-in-cache","errorCode":null,"errorMessage":"{key!r} not found in cache","messagePattern":"(.+?) not found in cache","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/cache.py","lineNumber":65,"sourceCode":"        >>> cache.get(\"xyz\", \"not found\")\n        'not found'\n        \"\"\"\n        self._items: OrderedDict[K, V] = OrderedDict()\n        self.maxsize = maxsize\n\n    def __bool__(self) -> bool:\n        \"\"\"Returns True if the cache is not empty, False otherwise.\"\"\"\n        return bool(self._items)\n\n    def __contains__(self, key: Any) -> bool:\n        \"\"\"Check if the key is in the cache.\"\"\"\n        return key in self._items\n\n    def __delitem__(self, key: K) -> None:\n        \"\"\"Remove the item with the specified key from the cache.\"\"\"\n        if key not in self._items:\n            msg = f\"{key!r} not found in cache\"\n            raise KeyError(msg)\n        del self._items[key]\n\n    def __getitem__(self, key: K) -> V:\n        \"\"\"Raises KeyError if the key is not found.\"\"\"\n        if key not in self._items:\n            msg = f\"{key!r} not found in cache\"\n            raise KeyError(msg)\n\n        # moving accessed items to the end marks them as recently used\n        self._items.move_to_end(key)\n        return self._items[key]\n\n    def __iter__(self) -> Iterator[K]:\n        \"\"\"Iterate over the keys in the cache.\"\"\"\n        yield from self._items\n\n    def __len__(self) -> int:\n        \"\"\"Number of items in the cache.\"\"\"","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/_utils/cache.py#L47-L83","documentation":"KeyError raised by __delitem__ on the LRU cache in _utils/cache.py: code attempted to remove key {key!r} that is not present in the OrderedDict backing the cache. It is a sentinel guard for callers mutating the cache with stale or already-evicted keys.","triggerScenarios":"Looking up a key that is not present in the cache.","commonSituations":"See trigger scenarios.","solutions":["The cache key does not exist (already evicted or never stored); check the key before access or recompute the value."],"exampleFix":"value = cache.get(key) or recompute(key)","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}