Ticket #10646: memcached_valueerrors.patch

File memcached_valueerrors.patch, 1.3 KB (added by andrewfong, 15 years ago)

A proposed better patch

  • django/core/cache/backends/memcached.py

     
    4646        self._cache.disconnect_all()
    4747
    4848    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
    5061
    5162    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
Back to Top