KeyError when using 8.x
luisdavim opened this issue · comments
Hi, I was trying to update my dependencies and started getting a KeyError
when using any 8.x version, I was using cachetools~=5.3.0
and CacheToolsUtils~=6.0
; tried to update to cachetools~=5.3.2
and CacheToolsUtils~=8.2
and started getting errors, the same code works fine with cachetools~=5.3.2
and CacheToolsUtils~=7.0
.
I'm using the TwoLevelCache
with a local map and Redis and the same error occurs regardless of setting resilient
to True
or not.
The error details, on the first call to the cached method (using the decorator):
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 68, in __getitem__
return self.__data[key]
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 216, in __getitem__
return self._cache.__getitem__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 418, in __getitem__
return cache_getitem(self, key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 70, in __getitem__
return self.__missing__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 97, in __missing__
raise KeyError(key)
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 219, in __getitem__
val = self._cache2.__getitem__(key)
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 488, in __getitem__
raise KeyError()
KeyError
and on the second call:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 68, in __getitem__
return self.__data[key]
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 216, in __getitem__
return self._cache.__getitem__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 418, in __getitem__
return cache_getitem(self, key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 70, in __getitem__
return self.__missing__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 97, in __missing__
raise KeyError(key)
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 219, in __getitem__
val = self._cache2.__getitem__(key)
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 488, in __getitem__
raise KeyError()
KeyError
{"asctime": "2023-11-08 18:04:01,481", "levelname": "INFO", "message": "find_ticket_by_hash received a request", "hash": "ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72"}
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 68, in __getitem__
return self.__data[key]
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 216, in __getitem__
return self._cache.__getitem__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 418, in __getitem__
return cache_getitem(self, key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 70, in __getitem__
return self.__missing__(key)
File "/usr/lib/python3.10/site-packages/cachetools/__init__.py", line 97, in __missing__
raise KeyError(key)
KeyError: ('ca07b064874e1b243a8edab3ff97e9e32d1420dee27ca974fbf92a36e94dac72',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 219, in __getitem__
val = self._cache2.__getitem__(key)
File "/usr/lib/python3.10/site-packages/CacheToolsUtils.py", line 488, in __getitem__
raise KeyError()
KeyError
Would you have a simple scripts which triggers the error?
The fact that key errors are raised if the data is not cached is expected, so I need to understand the outside context. Which decorator is used? A code sample would help avoid random guessing.
Sure, I'll try to create a minimal script to reproduce, this happens on the first call to the decorated method so there's nothing cached yet.
I got it, this is just a verbosity issue, the cache is working as expected.
Verbosity issue hopefully fixed in 8.3.
Thanks, I'll give it a try tomorrow and let you know.
I can confirm the issue is solved, thanks 👍