Raise NotFoundError with additional info#13
Conversation
| self._pop_item(key) | ||
| logger.debug("Element %s removed from cache - TTL expired", key) | ||
| return None | ||
| raise NotFoundError(key, message="Key removed from cache - TTL expired") |
There was a problem hiding this comment.
Cюда может быть другой эксепшен сделать, связанный с TTL?
There was a problem hiding this comment.
можно да, от этого ексепшена сделать еще один, который будет использоваться когда значение есть но протухло
fast_cache_middleware/exceptions.py
Outdated
| pass | ||
|
|
||
|
|
||
| class NotFoundError(StorageError): |
There was a problem hiding this comment.
лучше что то типа NotFoundStorageError или что то такое
fast_cache_middleware/controller.py
Outdated
|
|
||
| try: | ||
| result = await storage.get(cache_key) | ||
| except NotFoundError as e: |
There was a problem hiding this comment.
стоит ли здесь ловить? может пусть летит до мидлвари? как будто код проще тогда будет, без проверок на None
There was a problem hiding this comment.
Пока делал думал об этом.
А точно ли будет всё это долетать до мидлваря и информировать что с данными что-то не так.
| self._pop_item(key) | ||
| logger.debug("Element %s removed from cache - TTL expired", key) | ||
| return None | ||
| raise NotFoundError(key, message="Key removed from cache - TTL expired") |
There was a problem hiding this comment.
можно да, от этого ексепшена сделать еще один, который будет использоваться когда значение есть но протухло
|
bugbot run |
There was a problem hiding this comment.
Bugbot free trial expires on July 29, 2025
Learn more in the Cursor dashboard.
| ) | ||
| return None | ||
|
|
||
| return self._serializer.loads(raw_data) |
There was a problem hiding this comment.
Bug: Redis Storage Fails on Deserialization Errors
The RedisStorage.get method no longer handles deserialization errors. Previously, exceptions from self._serializer.loads(raw_data) (e.g., ValueError, JSONDecodeError) were caught, logged as warnings, and None was returned. Now, these exceptions propagate uncaught, potentially crashing the application when corrupted data is encountered in the cache, as the calling code expects NotFoundError for missing keys but not other serialization failures.
Locations (1)
| assert result is None # Элемент должен быть удален | ||
| with pytest.raises(NotFoundError): | ||
| result = await storage.get("test_key") | ||
| assert result is None # Элемент должен быть удален |
There was a problem hiding this comment.
Bug: Unreachable Assertion in Exception Handling
The assert result is None statement on line 102 is unreachable code. It is located within a pytest.raises(NotFoundError) context, meaning that if await storage.get("test_key") raises the expected NotFoundError, execution exits the block, preventing the assertion from being reached. If no exception is raised, pytest.raises will fail the test before the assertion is executed.
Locations (1)
| full_key = self._full_key(key) | ||
|
|
||
| if not await self._storage.exists(full_key): | ||
| raise TTLExpiredStorageError(full_key) |
There was a problem hiding this comment.
Сюда добавил проверку на существование ключа, аналогично тому, что сделано в in_memory решении. Если это избыточно и хватит простой проверки на наличие данных, которая ниже ( 80 строчка ), то уберу.
Resolve #11