summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-07-05 09:10:58 +0000
committerJannis Leidel <jannis@leidel.info>2011-07-05 09:10:58 +0000
commit90b6181657eafe1601ee90e4af26cd32cb301fb4 (patch)
treeedc1c3059895cd90acfcbd31cf1b4aa9196a1cd5
parent6de65ab76ff7704c90c6de9d5954c7736325c3fb (diff)
Fixed #16410 -- Fixed get_cache to behave gracefully when given a string that can't be split. Thanks, jedie.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16511 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/cache/__init__.py6
-rw-r--r--tests/regressiontests/cache/tests.py19
2 files changed, 21 insertions, 4 deletions
diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py
index b76ddcf038..b97c7469bb 100644
--- a/django/core/cache/__init__.py
+++ b/django/core/cache/__init__.py
@@ -126,12 +126,12 @@ def parse_backend_conf(backend, **kwargs):
location = args.pop('LOCATION', '')
return backend, location, args
else:
- # Trying to import the given backend, in case it's a dotted path
- mod_path, cls_name = backend.rsplit('.', 1)
try:
+ # Trying to import the given backend, in case it's a dotted path
+ mod_path, cls_name = backend.rsplit('.', 1)
mod = importlib.import_module(mod_path)
backend_cls = getattr(mod, cls_name)
- except (AttributeError, ImportError):
+ except (AttributeError, ImportError, ValueError):
raise InvalidCacheBackendError("Could not find backend '%s'" % backend)
location = kwargs.pop('LOCATION', '')
return backend, location, kwargs
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index ad7a2f86dc..6f1aa0d24f 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -12,7 +12,7 @@ import warnings
from django.conf import settings
from django.core import management
from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
-from django.core.cache.backends.base import CacheKeyWarning
+from django.core.cache.backends.base import CacheKeyWarning, InvalidCacheBackendError
from django.db import connections, router
from django.http import HttpResponse, HttpRequest, QueryDict
from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware, CacheMiddleware
@@ -938,6 +938,23 @@ class CustomCacheKeyValidationTests(unittest.TestCase):
cache.set(key, val)
self.assertEqual(cache.get(key), val)
+
+class GetCacheTests(unittest.TestCase):
+
+ def test_simple(self):
+ cache = get_cache('locmem://')
+ from django.core.cache.backends.locmem import LocMemCache
+ self.assertTrue(isinstance(cache, LocMemCache))
+
+ from django.core.cache import cache
+ self.assertTrue(isinstance(cache, get_cache('default').__class__))
+
+ cache = get_cache(
+ 'django.core.cache.backends.dummy.DummyCache', **{'TIMEOUT': 120})
+ self.assertEqual(cache.default_timeout, 120)
+
+ self.assertRaises(InvalidCacheBackendError, get_cache, 'does_not_exist')
+
class CacheUtils(unittest.TestCase):
"""TestCase for django.utils.cache functions."""