1. Jannis Leidel
  2. johnny-cache


Jason Moiron  committed 24e77ab

added some code changes to check for possible issue described in #24; also added patch/unpatch aliases for enable/disable

  • Participants
  • Parent commits 83a3c8e
  • Branches default

Comments (0)

Files changed (4)

File .hgignore

View file
  • Ignore whitespace
 syntax: glob

File johnny/cache.py

View file
  • Ignore whitespace
     tables will not be invalidated properly.  Use Carefully."""
+patch,unpatch = enable,disable
 def invalidate(*tables, **kwargs):
     """Invalidate the current generation for one or more tables.  The arguments
     can be either strings representing database table names or models.  Pass in
                     tables += get_tables_for_query(item.query)
         return tables
-    if (query.where and query.where.children and
-            isinstance(query.where.children[0], WhereNode)):
-        where_node = query.where.children[0]
-        tables = get_tables(where_node, tables)
+    if query.where and query.where.children:
+        where_nodes = [c for c in query.where.children if isinstance(c, WhereNode)]
+        for node in where_nodes:
+            tables += get_tables(node, tables)
     return list(set(tables))

File johnny/tests/cache.py

View file
  • Ignore whitespace
 class SingleModelTest(QueryCacheBase):
     fixtures = base.johnny_fixtures
+    def test_multi_where_cache_coherency(self):
+        """A test to detect the issue described in bitbucket #24:
+        https://bitbucket.org/jmoiron/johnny-cache/issue/24/
+        """
+        from testapp.models import Issue24Model as i24m
+        i24m.objects.get_or_create(one=1, two=1)
+        i24m.objects.get_or_create(one=1, two=2)
+        i24m.objects.get_or_create(one=2, two=1)
+        i24m.objects.get_or_create(one=2, two=2)
+        ones = i24m.objects.filter(one=1)
+        twos = i24m.objects.filter(two=1)
+        res = i24m.objects.filter(one__in=ones).exclude(two=twos).all()
+        # XXX: I'm afraid I don't even understand what this is supposed
+        # to be doing here, and in any case this test case fails.  I've
+        # included something similar to the patch in #24, if someone knows
+        # how to write a test case to create that condition please do so here
     def test_basic_querycaching(self):
         """A basic test that querycaching is functioning properly and is
         being invalidated properly on singular table reads & writes."""

File johnny/tests/testapp/models.py

View file
  • Ignore whitespace
 #from basic.people.models import Person
+class Issue24Model(models.Model):
+    one = models.PositiveIntegerField()
+    two = models.PositiveIntegerField()
 class User(models.Model):
     """User model."""
     first_name = models.CharField('first name', blank=True, max_length=128)