Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored December 27, 2011
4  django/utils/cache.py
@@ -165,7 +165,9 @@ def _i18n_cache_key_suffix(request, cache_key):
165 165
         # which in turn can also fall back to settings.LANGUAGE_CODE
166 166
         cache_key += '.%s' % getattr(request, 'LANGUAGE_CODE', get_language())
167 167
     if settings.USE_TZ:
168  
-        cache_key += '.%s' % get_current_timezone_name()
  168
+        # Windows uses non-standard timezone names that may include spaces,
  169
+        # which triggers CacheKeyWarning.
  170
+        cache_key += '.%s' % get_current_timezone_name().replace(' ', '_')
169 171
     return cache_key
170 172
 
171 173
 def _generate_cache_key(request, method, headerlist, key_prefix):
4  tests/regressiontests/cache/tests.py
@@ -1270,7 +1270,7 @@ def test_cache_key_i18n_formatting(self):
1270 1270
     @override_settings(USE_I18N=False, USE_L10N=False, USE_TZ=True)
1271 1271
     def test_cache_key_i18n_timezone(self):
1272 1272
         request = self._get_request()
1273  
-        tz = timezone.get_current_timezone_name()
  1273
+        tz = timezone.get_current_timezone_name().replace(' ', '_')
1274 1274
         response = HttpResponse()
1275 1275
         key = learn_cache_key(request, response)
1276 1276
         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):
1281 1281
     def test_cache_key_no_i18n (self):
1282 1282
         request = self._get_request()
1283 1283
         lang = translation.get_language()
1284  
-        tz = timezone.get_current_timezone_name()
  1284
+        tz = timezone.get_current_timezone_name().replace(' ', '_')
1285 1285
         response = HttpResponse()
1286 1286
         key = learn_cache_key(request, response)
1287 1287
         self.assertNotIn(lang, key, "Cache keys shouldn't include the language name when i18n isn't active")

0 notes on commit e8a6fee

Please sign in to comment.
Something went wrong with that request. Please try again.