Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14423 -- corrected incorrect SQL being generated when a nullab…

…le, inherited field was used in an exclude. Thanks to PhiR_42 for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14600 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0eb31d3dc9435b18680f7a41bc9067685beb8344 1 parent c0248f6
Alex Gaynor authored November 17, 2010
10  django/db/models/sql/query.py
@@ -921,8 +921,7 @@ def add_aggregate(self, aggregate, model, alias, is_summary):
921 921
         """
922 922
         opts = model._meta
923 923
         field_list = aggregate.lookup.split(LOOKUP_SEP)
924  
-        if (len(field_list) == 1 and
925  
-            aggregate.lookup in self.aggregates.keys()):
  924
+        if len(field_list) == 1 and aggregate.lookup in self.aggregates:
926 925
             # Aggregate is over an annotation
927 926
             field_name = field_list[0]
928 927
             col = field_name
@@ -1090,11 +1089,14 @@ def add_filter(self, filter_expr, connector=AND, negate=False, trim=False,
1090 1089
                         if self.alias_map[alias][JOIN_TYPE] == self.LOUTER:
1091 1090
                             j_col = self.alias_map[alias][RHS_JOIN_COL]
1092 1091
                             entry = self.where_class()
1093  
-                            entry.add((Constraint(alias, j_col, None), 'isnull', True), AND)
  1092
+                            entry.add(
  1093
+                                (Constraint(alias, j_col, None), 'isnull', True),
  1094
+                                AND
  1095
+                            )
1094 1096
                             entry.negate()
1095 1097
                             self.where.add(entry, AND)
1096 1098
                             break
1097  
-                elif not (lookup_type == 'in'
  1099
+                if not (lookup_type == 'in'
1098 1100
                             and not hasattr(value, 'as_sql')
1099 1101
                             and not hasattr(value, '_as_sql')
1100 1102
                             and not value) and field.null:
34  tests/regressiontests/model_inheritance_regress/tests.py
@@ -3,12 +3,16 @@
3 3
 """
4 4
 
5 5
 import datetime
  6
+from operator import attrgetter
  7
+
6 8
 from django.test import TestCase
7  
-from regressiontests.model_inheritance_regress.models import (
8  
-    Place, Restaurant, ItalianRestaurant, ParkingLot, ParkingLot2,
9  
-    ParkingLot3, Supplier, Wholesaler, Child, SelfRefChild, ArticleWithAuthor,
10  
-    M2MChild, QualityControl, DerivedM, Person, BirthdayParty, BachelorParty,
11  
-    MessyBachelorParty, InternalCertificationAudit)
  9
+
  10
+from models import (Place, Restaurant, ItalianRestaurant, ParkingLot,
  11
+    ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
  12
+    SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
  13
+    Person, BirthdayParty, BachelorParty, MessyBachelorParty,
  14
+    InternalCertificationAudit)
  15
+
12 16
 
13 17
 class ModelInheritanceTest(TestCase):
14 18
     def test_model_inheritance(self):
@@ -355,7 +359,10 @@ def test_abstract_base_class_m2m_relation_inheritance(self):
355 359
         self.assertEqual(parties, [bachelor, messy_parent])
356 360
 
357 361
     def test_11369(self):
358  
-        """verbose_name_plural correctly inherited from ABC if inheritance chain includes an abstract model."""
  362
+        """
  363
+        verbose_name_plural correctly inherited from ABC if inheritance chain
  364
+        includes an abstract model.
  365
+        """
359 366
         # Regression test for #11369: verbose_name_plural should be inherited
360 367
         # from an ABC even when there are one or more intermediate
361 368
         # abstract models in the inheritance chain, for consistency with
@@ -364,3 +371,18 @@ def test_11369(self):
364 371
                 InternalCertificationAudit._meta.verbose_name_plural,
365 372
                 u'Audits'
366 373
         )
  374
+
  375
+    def test_inherited_nullable_exclude(self):
  376
+        obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
  377
+        self.assertQuerysetEqual(
  378
+            SelfRefParent.objects.exclude(self_data=72), [
  379
+                obj.pk
  380
+            ],
  381
+            attrgetter("pk")
  382
+        )
  383
+        self.assertQuerysetEqual(
  384
+            SelfRefChild.objects.exclude(self_data=72), [
  385
+                obj.pk
  386
+            ],
  387
+            attrgetter("pk")
  388
+        )

0 notes on commit 0eb31d3

Please sign in to comment.
Something went wrong with that request. Please try again.