Author: Alex
Date: 2010-11-17 10:46:50 -0600 (Wed, 17 Nov 2010)
New Revision: 14600

Modified:
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/regressiontests/model_inheritance_regress/tests.py
Log:
Fixed #14423 -- corrected incorrect SQL being generated when a nullable, 
inherited field was used in an exclude.  Thanks to PhiR_42 for the patch.

Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py  2010-11-17 16:11:17 UTC (rev 
14599)
+++ django/trunk/django/db/models/sql/query.py  2010-11-17 16:46:50 UTC (rev 
14600)
@@ -921,8 +921,7 @@
         """
         opts = model._meta
         field_list = aggregate.lookup.split(LOOKUP_SEP)
-        if (len(field_list) == 1 and
-            aggregate.lookup in self.aggregates.keys()):
+        if len(field_list) == 1 and aggregate.lookup in self.aggregates:
             # Aggregate is over an annotation
             field_name = field_list[0]
             col = field_name
@@ -1090,11 +1089,14 @@
                         if self.alias_map[alias][JOIN_TYPE] == self.LOUTER:
                             j_col = self.alias_map[alias][RHS_JOIN_COL]
                             entry = self.where_class()
-                            entry.add((Constraint(alias, j_col, None), 
'isnull', True), AND)
+                            entry.add(
+                                (Constraint(alias, j_col, None), 'isnull', 
True),
+                                AND
+                            )
                             entry.negate()
                             self.where.add(entry, AND)
                             break
-                elif not (lookup_type == 'in'
+                if not (lookup_type == 'in'
                             and not hasattr(value, 'as_sql')
                             and not hasattr(value, '_as_sql')
                             and not value) and field.null:

Modified: django/trunk/tests/regressiontests/model_inheritance_regress/tests.py
===================================================================
--- django/trunk/tests/regressiontests/model_inheritance_regress/tests.py       
2010-11-17 16:11:17 UTC (rev 14599)
+++ django/trunk/tests/regressiontests/model_inheritance_regress/tests.py       
2010-11-17 16:46:50 UTC (rev 14600)
@@ -3,13 +3,17 @@
 """
 
 import datetime
+from operator import attrgetter
+
 from django.test import TestCase
-from regressiontests.model_inheritance_regress.models import (
-    Place, Restaurant, ItalianRestaurant, ParkingLot, ParkingLot2,
-    ParkingLot3, Supplier, Wholesaler, Child, SelfRefChild, ArticleWithAuthor,
-    M2MChild, QualityControl, DerivedM, Person, BirthdayParty, BachelorParty,
-    MessyBachelorParty, InternalCertificationAudit)
 
+from models import (Place, Restaurant, ItalianRestaurant, ParkingLot,
+    ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
+    SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
+    Person, BirthdayParty, BachelorParty, MessyBachelorParty,
+    InternalCertificationAudit)
+
+
 class ModelInheritanceTest(TestCase):
     def test_model_inheritance(self):
         # Regression for #7350, #7202
@@ -355,7 +359,10 @@
         self.assertEqual(parties, [bachelor, messy_parent])
 
     def test_11369(self):
-        """verbose_name_plural correctly inherited from ABC if inheritance 
chain includes an abstract model."""
+        """
+        verbose_name_plural correctly inherited from ABC if inheritance chain
+        includes an abstract model.
+        """
         # Regression test for #11369: verbose_name_plural should be inherited
         # from an ABC even when there are one or more intermediate
         # abstract models in the inheritance chain, for consistency with
@@ -364,3 +371,18 @@
                 InternalCertificationAudit._meta.verbose_name_plural,
                 u'Audits'
         )
+
+    def test_inherited_nullable_exclude(self):
+        obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
+        self.assertQuerysetEqual(
+            SelfRefParent.objects.exclude(self_data=72), [
+                obj.pk
+            ],
+            attrgetter("pk")
+        )
+        self.assertQuerysetEqual(
+            SelfRefChild.objects.exclude(self_data=72), [
+                obj.pk
+            ],
+            attrgetter("pk")
+        )

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to