# HG changeset patch # User RhodeCode Admin # Date 2023-05-11 10:11:16 # Node ID b2c2c0f32b84c87e1086a79f9c8d35654aed0b66 # Parent a562499c6af4c7fdfce8c70e55c5a06af4b93f1c caches: dbm backend needs to use bytes to list keys diff --git a/rhodecode/lib/rc_cache/backends.py b/rhodecode/lib/rc_cache/backends.py --- a/rhodecode/lib/rc_cache/backends.py +++ b/rhodecode/lib/rc_cache/backends.py @@ -41,7 +41,7 @@ from dogpile.cache.api import Serializer from pyramid.settings import asbool from rhodecode.lib.memory_lru_dict import LRUDict, LRUDictDebug -from rhodecode.lib.str_utils import safe_str +from rhodecode.lib.str_utils import safe_str, safe_bytes _default_max_size = 1024 @@ -146,20 +146,20 @@ class FileNamespaceBackend(PickleSeriali def __repr__(self): return '{} `{}`'.format(self.__class__, self.filename) - def list_keys(self, prefix=''): - prefix = '{}:{}'.format(self.key_prefix, prefix) + def list_keys(self, prefix: bytes = b''): + prefix = b'%b:%b' % (safe_bytes(self.key_prefix), safe_bytes(prefix)) - def cond(v): + def cond(dbm_key: bytes): if not prefix: return True - if v.startswith(prefix): + if dbm_key.startswith(prefix): return True return False with self._dbm_file(True) as dbm: try: - return list(filter(cond, list(dbm.keys()))) + return list(filter(cond, dbm.keys())) except Exception: log.error('Failed to fetch DBM keys from DB: %s', self.get_store()) raise