Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10646: `cache.incr()` and `decr()` now fail consistantly under…

… python-memcache and cmemcache.

Though it looks like this commit has no tests that's not so: this is tested for in `regressiontests/cache/tests.py` around like 183; these tests currently fail if ran against cmemcache.

Thanks, andrewfong.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 07ba0dbaf75a72c3c3ab71ca5a80f0889ddabb72 1 parent 1c5fe46
Jacob Kaplan-Moss authored December 13, 2009

Showing 1 changed file with 23 additions and 2 deletions. Show diff stats Hide diff stats

  1. 25  django/core/cache/backends/memcached.py
25  django/core/cache/backends/memcached.py
@@ -46,7 +46,28 @@ def close(self, **kwargs):
46 46
         self._cache.disconnect_all()
47 47
 
48 48
     def incr(self, key, delta=1):
49  
-        return self._cache.incr(key, delta)
  49
+        try:
  50
+            val = self._cache.incr(key, delta)
  51
+
  52
+        # python-memcache responds to incr on non-existent keys by
  53
+        # raising a ValueError. Cmemcache returns None. In both
  54
+        # cases, we should raise a ValueError though.
  55
+        except ValueError:
  56
+            val = None
  57
+        if val is None:
  58
+            raise ValueError("Key '%s' not found" % key)
  59
+
  60
+        return val
50 61
 
51 62
     def decr(self, key, delta=1):
52  
-        return self._cache.decr(key, delta)
  63
+        try:
  64
+            val = self._cache.decr(key, delta)
  65
+
  66
+        # python-memcache responds to decr on non-existent keys by
  67
+        # raising a ValueError. Cmemcache returns None. In both
  68
+        # cases, we should raise a ValueError though.
  69
+        except ValueError:
  70
+            val = None
  71
+        if val is None:
  72
+            raise ValueError("Key '%s' not found" % key)
  73
+        return val

0 notes on commit 07ba0db

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