Code

Ticket #12823: 12823_trunk.diff

File 12823_trunk.diff, 2.4 KB (added by PhiR_42, 4 years ago)

patch and test vs trunk

Line 
1diff -ur orig.trunk/django/db/models/sql/query.py trunk/django/db/models/sql/query.py
2--- orig.trunk/django/db/models/sql/query.py    2010-12-15 19:09:14.000000000 +0100
3+++ trunk/django/db/models/sql/query.py 2010-12-15 19:37:44.000000000 +0100
4@@ -1443,7 +1443,8 @@
5         query.bump_prefix()
6         query.clear_ordering(True)
7         query.set_start(prefix)
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
14diff -ur orig.trunk/tests/regressiontests/queries/tests.py trunk/tests/regressiontests/queries/tests.py
15--- orig.trunk/tests/regressiontests/queries/tests.py   2010-12-15 19:09:23.000000000 +0100
16+++ trunk/tests/regressiontests/queries/tests.py        2010-12-15 19:42:45.000000000 +0100
17@@ -42,15 +42,15 @@
18         n2 = Note.objects.create(note='n2', misc='bar', id=2)
19         self.n3 = Note.objects.create(note='n3', misc='foo', id=3)
20 
21-        ann1 = Annotation.objects.create(name='a1', tag=self.t1)
22+        ann1 = Annotation.objects.create(name='a1', tag=self.t1, id=11)
23         ann1.notes.add(self.n1)
24-        ann2 = Annotation.objects.create(name='a2', tag=t4)
25+        ann2 = Annotation.objects.create(name='a2', tag=t4, id=12)
26         ann2.notes.add(n2, self.n3)
27 
28         # Create these out of order so that sorting by 'id' will be different to sorting
29         # by 'info'. Helps detect some problems later.
30-        self.e2 = ExtraInfo.objects.create(info='e2', note=n2)
31-        e1 = ExtraInfo.objects.create(info='e1', note=self.n1)
32+        self.e2 = ExtraInfo.objects.create(info='e2', note=n2, id=22)
33+        e1 = ExtraInfo.objects.create(info='e1', note=self.n1, id=21)
34 
35         self.a1 = Author.objects.create(name='a1', num=1001, extra=e1)
36         self.a2 = Author.objects.create(name='a2', num=2002, extra=e1)
37@@ -80,6 +80,12 @@
38         Cover.objects.create(title="first", item=i4)
39         Cover.objects.create(title="second", item=self.i2)
40 
41+    def test_ticket12823(self):
42+        self.assertQuerysetEqual(
43+            Author.objects.exclude(extra__note__annotation__name ='a2'),
44+            ['<Author: a1>', '<Author: a2>']
45+        )
46+       
47     def test_ticket1050(self):
48         self.assertQuerysetEqual(
49             Item.objects.filter(tags__isnull=True),