diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 613f4c4..c2c3d7a 100644
a
|
b
|
class Query(object):
|
1229 | 1229 | self.promote_joins(join_list) |
1230 | 1230 | if lookup_type != 'isnull': |
1231 | 1231 | if len(join_list) > 1: |
1232 | | for alias in join_list: |
1233 | | if self.alias_map[alias].join_type == self.LOUTER: |
1234 | | j_col = self.alias_map[alias].rhs_join_col |
| 1232 | for j_alias in join_list: |
| 1233 | if self.alias_map[j_alias].join_type == self.LOUTER: |
| 1234 | j_col = self.alias_map[j_alias].rhs_join_col |
1235 | 1235 | # The join promotion logic should never produce |
1236 | 1236 | # a LOUTER join for the base join - assert that. |
1237 | 1237 | assert j_col is not None |
1238 | 1238 | entry = self.where_class() |
1239 | 1239 | entry.add( |
1240 | | (Constraint(alias, j_col, None), 'isnull', True), |
| 1240 | (Constraint(j_alias, j_col, None), 'isnull', True), |
1241 | 1241 | AND |
1242 | 1242 | ) |
1243 | 1243 | entry.negate() |
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 16583e8..5bccb49 100644
a
|
b
|
class Annotation(models.Model):
|
64 | 64 | class ExtraInfo(models.Model): |
65 | 65 | info = models.CharField(max_length=100) |
66 | 66 | note = models.ForeignKey(Note) |
| 67 | value = models.IntegerField(null=True) |
67 | 68 | |
68 | 69 | class Meta: |
69 | 70 | ordering = ['info'] |
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 4adf076..272b692 100644
a
|
b
|
class Queries1Tests(BaseQuerysetTest):
|
52 | 52 | |
53 | 53 | # Create these out of order so that sorting by 'id' will be different to sorting |
54 | 54 | # by 'info'. Helps detect some problems later. |
55 | | self.e2 = ExtraInfo.objects.create(info='e2', note=n2) |
56 | | e1 = ExtraInfo.objects.create(info='e1', note=self.n1) |
| 55 | self.e2 = ExtraInfo.objects.create(info='e2', note=n2, value=41) |
| 56 | e1 = ExtraInfo.objects.create(info='e1', note=self.n1, value=42) |
57 | 57 | |
58 | 58 | self.a1 = Author.objects.create(name='a1', num=1001, extra=e1) |
59 | 59 | self.a2 = Author.objects.create(name='a2', num=2002, extra=e1) |
… |
… |
class Queries1Tests(BaseQuerysetTest):
|
1106 | 1106 | self.assertTrue(str(q3.query).count('LEFT OUTER JOIN') == 1) |
1107 | 1107 | self.assertTrue(str(q3.query).count('INNER JOIN') == 0) |
1108 | 1108 | |
| 1109 | def test_ticket19672(self): |
| 1110 | self.assertQuerysetEqual( |
| 1111 | Report.objects.filter(Q(creator__isnull=False)& |
| 1112 | ~Q(creator__extra__value=41)), |
| 1113 | ['<Report: r1>'] |
| 1114 | ) |
| 1115 | |
1109 | 1116 | |
1110 | 1117 | class Queries2Tests(TestCase): |
1111 | 1118 | def setUp(self): |