From 926148ef019abcac3a9988c78734d9336d69f24e Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 5 Jun 2020 07:21:52 +0200 Subject: [PATCH] Fixed #31654 -- Fixed cache key validation messages. --- django/core/cache/backends/base.py | 2 +- docs/releases/2.2.14.txt | 13 +++++++++++++ docs/releases/3.0.8.txt | 3 ++- docs/releases/index.txt | 1 + tests/cache/tests.py | 6 ++++-- 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 docs/releases/2.2.14.txt diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index 8322172fc1..f360f4f57a 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -287,6 +287,6 @@ def memcache_key_warnings(key): if ord(char) < 33 or ord(char) == 127: yield ( 'Cache key contains characters that will cause errors if ' - 'used with memcached: %r' % key, CacheKeyWarning + 'used with memcached: %r' % key ) break diff --git a/docs/releases/2.2.14.txt b/docs/releases/2.2.14.txt new file mode 100644 index 0000000000..0c7232fe08 --- /dev/null +++ b/docs/releases/2.2.14.txt @@ -0,0 +1,13 @@ +=========================== +Django 2.2.14 release notes +=========================== + +*Expected July 1, 2020* + +Django 2.2.14 fixes a bug in 2.2.13. + +Bugfixes +======== + +* Fixed messages of ``InvalidCacheKey`` exceptions and ``CacheKeyWarning`` + warnings raised by cache key validation (:ticket:`31654`). diff --git a/docs/releases/3.0.8.txt b/docs/releases/3.0.8.txt index 99247a4355..e355f0a0ff 100644 --- a/docs/releases/3.0.8.txt +++ b/docs/releases/3.0.8.txt @@ -9,4 +9,5 @@ Django 3.0.8 fixes several bugs in 3.0.7. Bugfixes ======== -* ... +* Fixed messages of ``InvalidCacheKey`` exceptions and ``CacheKeyWarning`` + warnings raised by cache key validation (:ticket:`31654`). diff --git a/docs/releases/index.txt b/docs/releases/index.txt index 70a977491d..6a5d46bc8c 100644 --- a/docs/releases/index.txt +++ b/docs/releases/index.txt @@ -54,6 +54,7 @@ versions of the documentation contain the release notes for any later releases. .. toctree:: :maxdepth: 1 + 2.2.14 2.2.13 2.2.12 2.2.11 diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 75fd7853de..d404475e16 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -637,8 +637,9 @@ class BaseCacheTests: cache.key_func = func try: - with self.assertWarnsMessage(CacheKeyWarning, expected_warning): + with self.assertWarns(CacheKeyWarning) as cm: cache.set(key, 'value') + self.assertEqual(str(cm.warning), expected_warning) finally: cache.key_func = old_func @@ -1276,8 +1277,9 @@ class BaseMemcachedTests(BaseCacheTests): key. """ msg = expected_warning.replace(key, cache.make_key(key)) - with self.assertRaisesMessage(InvalidCacheKey, msg): + with self.assertRaises(InvalidCacheKey) as cm: cache.set(key, 'value') + self.assertEqual(str(cm.exception), msg) def test_default_never_expiring_timeout(self): # Regression test for #22845