# HG changeset patch # User Marcin Kuzminski # Date 2016-06-28 14:58:55 # Node ID 3df2eb52ee4ee71ffa966d433a689b8f8078a232 # Parent 6aa02ab518ee0012c8af4aa20138751bab1f8915 caches: make sure __repr__ of invalidaiton context always return strings. - this is a part of python specs, otherwise we potentially can cause UnicodeDecodeErrors diff --git a/rhodecode/lib/caches.py b/rhodecode/lib/caches.py --- a/rhodecode/lib/caches.py +++ b/rhodecode/lib/caches.py @@ -167,7 +167,7 @@ class FreshRegionCache(ActiveRegionCache class InvalidationContext(object): def __repr__(self): return ''.format( - self.repo_name, self.cache_type) + safe_str(self.repo_name), safe_str(self.cache_type)) def __init__(self, compute_func, repo_name, cache_type, raise_exception=False): diff --git a/rhodecode/tests/other/test_libs.py b/rhodecode/tests/other/test_libs.py --- a/rhodecode/tests/other/test_libs.py +++ b/rhodecode/tests/other/test_libs.py @@ -432,7 +432,13 @@ def test_get_repo_by_id(test, expected): assert _test == expected -def test_invalidation_context(pylonsapp): +@pytest.mark.parametrize("test_repo_name, repo_type", [ + ("test_repo_1", None), + ("repo_group/foobar", None), + ("test_non_asci_ąćę", None), + (u"test_non_asci_unicode_ąćę", None), +]) +def test_invalidation_context(pylonsapp, test_repo_name, repo_type): from beaker.cache import cache_region from rhodecode.lib import caches from rhodecode.model.db import CacheKey @@ -442,7 +448,7 @@ def test_invalidation_context(pylonsapp) return 'result' invalidator_context = CacheKey.repo_context_cache( - _dummy_func, 'test_repo_1', 'repo') + _dummy_func, test_repo_name, 'repo') with invalidator_context as context: invalidated = context.invalidate() @@ -452,6 +458,8 @@ def test_invalidation_context(pylonsapp) assert 'result' == result assert isinstance(context, caches.FreshRegionCache) + assert 'InvalidationContext' in repr(invalidator_context) + with invalidator_context as context: context.invalidate() result = context.compute()