Code

Ticket #12823: 12823_trunk.2.diff

File 12823_trunk.2.diff, 3.0 KB (added by PhiR, 3 years ago)

updated (sorry for the username change)

Line 
1diff -ur ./django/db/models/sql/query.py ../../patched_trunk//django/db/models/sql/query.py
2--- ./django/db/models/sql/query.py     2011-09-08 17:07:40.000000000 +0200
3+++ ../../patched_trunk//django/db/models/sql/query.py  2011-09-08 16:56:34.000000000 +0200
4@@ -1535,7 +1535,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@@ -1548,7 +1549,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):
23
24diff -ur ./tests/regressiontests/queries/tests.py ../../patched_trunk//tests/regressiontests/queries/tests.py
25--- ./tests/regressiontests/queries/tests.py    2011-09-08 17:08:13.000000000 +0200
26+++ ../../patched_trunk//tests/regressiontests/queries/tests.py 2011-09-08 17:00:28.000000000 +0200
27@@ -36,15 +36,15 @@
28         n2 = Note.objects.create(note='n2', misc='bar', id=2)
29         self.n3 = Note.objects.create(note='n3', misc='foo', id=3)
30 
31-        ann1 = Annotation.objects.create(name='a1', tag=self.t1)
32+        ann1 = Annotation.objects.create(name='a1', tag=self.t1, id=11)
33         ann1.notes.add(self.n1)
34-        ann2 = Annotation.objects.create(name='a2', tag=t4)
35+        ann2 = Annotation.objects.create(name='a2', tag=t4, id=12)
36         ann2.notes.add(n2, self.n3)
37 
38         # Create these out of order so that sorting by 'id' will be different to sorting
39         # by 'info'. Helps detect some problems later.
40-        self.e2 = ExtraInfo.objects.create(info='e2', note=n2)
41-        e1 = ExtraInfo.objects.create(info='e1', note=self.n1)
42+        self.e2 = ExtraInfo.objects.create(info='e2', note=n2, id=21)
43+        e1 = ExtraInfo.objects.create(info='e1', note=self.n1, id=22)
44 
45         self.a1 = Author.objects.create(name='a1', num=1001, extra=e1)
46         self.a2 = Author.objects.create(name='a2', num=2002, extra=e1)
47@@ -74,6 +74,13 @@
48         Cover.objects.create(title="first", item=i4)
49         Cover.objects.create(title="second", item=self.i2)
50 
51+    def test_ticket12823(self):
52+        #self.assertEqual(str(Author.objects.exclude(extra__note__annotation__name ='a2').query), "")
53+        self.assertQuerysetEqual(
54+            Author.objects.exclude(extra__note__annotation__name ='a2'),
55+            ['<Author: a1>', '<Author: a2>']
56+        )
57+
58     def test_ticket1050(self):
59         self.assertQuerysetEqual(
60             Item.objects.filter(tags__isnull=True),
61