Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a CacheKeyWarning under Windows.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e8a6fee6e66f9745e2580b329c93e369801a8318 1 parent b045783
Aymeric Augustin aaugustin authored
Showing with 5 additions and 3 deletions.
  1. +3 −1 django/utils/cache.py
  2. +2 −2 tests/regressiontests/cache/tests.py
4 django/utils/cache.py
View
@@ -165,7 +165,9 @@ def _i18n_cache_key_suffix(request, cache_key):
# which in turn can also fall back to settings.LANGUAGE_CODE
cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language())
if settings.USE_TZ:
- cache_key += '.%s' % get_current_timezone_name()
+ # Windows uses non-standard timezone names that may include spaces,
+ # which triggers CacheKeyWarning.
+ cache_key += '.%s' % get_current_timezone_name().replace(' ', '_')
return cache_key
def _generate_cache_key(request, method, headerlist, key_prefix):
4 tests/regressiontests/cache/tests.py
View
@@ -1270,7 +1270,7 @@ def test_cache_key_i18n_formatting(self):
@override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
def test_cache_key_i18n_timezone(self):
request = self._get_request()
- tz = timezone.get_current_timezone_name()
+ tz = timezone.get_current_timezone_name().replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
self.assertIn(tz, key, "Cache keys should include the time zone name when time zones are active")
@@ -1281,7 +1281,7 @@ def test_cache_key_i18n_timezone(self):
def test_cache_key_no_i18n (self):
request = self._get_request()
lang = translation.get_language()
- tz = timezone.get_current_timezone_name()
+ tz = timezone.get_current_timezone_name().replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
self.assertNotIn(lang, key, "Cache keys shouldn't include the language name when i18n isn't active")
Please sign in to comment.
Something went wrong with that request. Please try again.