Lau Bech Lauritzen avatar Lau Bech Lauritzen committed a8227d2 Merge

Merged

Comments (0)

Files changed (2)

         def newfun(cls, *args, **kwargs):
             db = getattr(cls, 'using', 'default')
             from django.db.models.sql import compiler
+            # we have to do this before we check the tables, since the tables
+            # are actually being set in the original function
+            ret = original(cls, *args, **kwargs)
+
             if type(cls) == compiler.SQLInsertCompiler:
                 #Inserts are a special case where cls.tables
                 #are not populated.
                 tables = cls.query.tables
             for table in tables:
                 self.keyhandler.invalidate_table(table, db)
-            return original(cls, *args, **kwargs)
+            return ret
         return newfun
 
 
                 # blacklisted, in which case we just don't care.
                 if key is not None:
                     self.cache_backend.set(key, result)
+            elif cls.tables and sql.startswith('UPDATE'):
+                # issue #1 in bitbucket, not invalidating on update
+                for table in cls.tables:
+                    self.keyhandler.invalidate_table(table)
             return result
         return newfun
 

johnny/tests/cache.py

         self.failUnless(new_count == 2)
         # this tests the codepath after 'except EmptyResultSet' where
         # result_type == MULTI
-        list(Publisher.objects.filter(title__in=[]))
+        self.failUnless(not list(Publisher.objects.filter(title__in=[])))
 
     def test_querycache_return_results(self):
         """Test that the return results from the query cache are what we
         Genre.objects.get(title='Fantasy')
         self.failUnless(not q.get_nowait())
 
+    def test_update(self):
+        from testapp.models import Genre
+        connection.queries = []
+        g1 = Genre.objects.get(pk=1)
+        Genre.objects.all().update(title="foo")
+        g2 = Genre.objects.get(pk=1)
+        self.failUnless(g1.title != g2.title)
+        self.failUnless(g2.title == "foo")
+        self.failUnless(len(connection.queries) == 3)
+
     def test_empty_count(self):
         """Test for an empty count aggregate query with an IN"""
         from testapp.models import Genre
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.