Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7967 -- Make sure the __contains__ method in the cache backend…

…s call the

right has_key() method for the subclass. Patch from Marty Alchin.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6f16b5bad2f714b88639ebb90d30fd6cef686cfc 1 parent f49c5c2
Malcolm Tredinnick authored July 26, 2008
9  django/core/cache/backends/base.py
@@ -63,4 +63,11 @@ def has_key(self, key):
63 63
         """
64 64
         return self.get(key) is not None
65 65
 
66  
-    __contains__ = has_key
  66
+    def __contains__(self, key):
  67
+        """
  68
+        Returns True if the key is in the cache and has not expired.
  69
+        """
  70
+        # This is a separate method, rather than just a copy of has_key(),
  71
+        # so that it always has the same functionality as has_key(), even
  72
+        # if a subclass overrides it.
  73
+        return self.has_key(key)
4  tests/regressiontests/cache/tests.py
@@ -56,11 +56,15 @@ def test_has_key(self):
56 56
         cache.set("hello1", "goodbye1")
57 57
         self.assertEqual(cache.has_key("hello1"), True)
58 58
         self.assertEqual(cache.has_key("goodbye1"), False)
  59
+        cache.set("empty", 'fred')
  60
+        self.assertEqual(cache.has_key("empty"), True)
59 61
 
60 62
     def test_in(self):
61 63
         cache.set("hello2", "goodbye2")
62 64
         self.assertEqual("hello2" in cache, True)
63 65
         self.assertEqual("goodbye2" in cache, False)
  66
+        cache.set("empty", 'fred')
  67
+        self.assertEqual("empty" in cache, True)
64 68
 
65 69
     def test_data_types(self):
66 70
         stuff = {

0 notes on commit 6f16b5b

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