Code

Ticket #12823: 12823_1.2.diff

File 12823_1.2.diff, 3.0 KB (added by PhiR, 3 years ago)
Line 
1diff -ur ../orig/Django-1.2.5//django/db/models/sql/query.py ./django/db/models/sql/query.py
2--- ../orig/Django-1.2.5//django/db/models/sql/query.py 2011-02-08 15:07:14.000000000 +0100
3+++ ./django/db/models/sql/query.py     2011-09-08 17:21:16.000000000 +0200
4@@ -1481,7 +1481,8 @@
5         alias, col = query.select[0]
6         query.where.add((Constraint(alias, col, None), 'isnull', False), AND)
7 
8-        self.add_filter(('%s__in' % prefix, query), negate=True, trim=True,
9+        new_prefix = prefix.split(LOOKUP_SEP)[0]
10+        self.add_filter(('%s__in' % new_prefix, query), negate=True, trim=True,
11                 can_reuse=can_reuse)
12 
13         # If there's more than one join in the inner query (before any initial
14@@ -1494,7 +1495,7 @@
15         active_positions = [pos for (pos, count) in
16                 enumerate(query.alias_refcount.itervalues()) if count]
17         if active_positions[-1] > 1:
18-            self.add_filter(('%s__isnull' % prefix, False), negate=True,
19+            self.add_filter(('%s__isnull' % new_prefix, False), negate=True,
20                     trim=True, can_reuse=can_reuse)
21 
22     def set_limits(self, low=None, high=None):
23diff -ur ../orig/Django-1.2.5//tests/regressiontests/queries/tests.py ./tests/regressiontests/queries/tests.py
24--- ../orig/Django-1.2.5//tests/regressiontests/queries/tests.py        2011-01-25 04:39:38.000000000 +0100
25+++ ./tests/regressiontests/queries/tests.py    2011-09-08 17:21:16.000000000 +0200
26@@ -48,15 +48,15 @@
27         n2 = Note.objects.create(note='n2', misc='bar', id=2)
28         self.n3 = Note.objects.create(note='n3', misc='foo', id=3)
29 
30-        ann1 = Annotation.objects.create(name='a1', tag=self.t1)
31+        ann1 = Annotation.objects.create(name='a1', tag=self.t1, id=11)
32         ann1.notes.add(self.n1)
33-        ann2 = Annotation.objects.create(name='a2', tag=t4)
34+        ann2 = Annotation.objects.create(name='a2', tag=t4, id=12)
35         ann2.notes.add(n2, self.n3)
36 
37         # Create these out of order so that sorting by 'id' will be different to sorting
38         # by 'info'. Helps detect some problems later.
39-        self.e2 = ExtraInfo.objects.create(info='e2', note=n2)
40-        e1 = ExtraInfo.objects.create(info='e1', note=self.n1)
41+        self.e2 = ExtraInfo.objects.create(info='e2', note=n2, id=21)
42+        e1 = ExtraInfo.objects.create(info='e1', note=self.n1, id=22)
43 
44         self.a1 = Author.objects.create(name='a1', num=1001, extra=e1)
45         self.a2 = Author.objects.create(name='a2', num=2002, extra=e1)
46@@ -86,6 +86,13 @@
47         Cover.objects.create(title="first", item=i4)
48         Cover.objects.create(title="second", item=self.i2)
49 
50+    def test_ticket12823(self):
51+        #self.assertEqual(str(Author.objects.exclude(extra__note__annotation__name ='a2').query), "")
52+        self.assertQuerysetEqual(
53+            Author.objects.exclude(extra__note__annotation__name ='a2'),
54+            ['<Author: a1>', '<Author: a2>']
55+        )
56+
57     def test_ticket1050(self):
58         self.assertQuerysetEqual(
59             Item.objects.filter(tags__isnull=True),