Author: mtredinnick
Date: 2008-12-06 23:50:26 -0600 (Sat, 06 Dec 2008)
New Revision: 9589

Modified:
   django/branches/releases/1.0.X/django/db/models/sql/query.py
   django/branches/releases/1.0.X/tests/regressiontests/queries/models.py
Log:
[1.0.X] Fixed #9188 -- Fixed a case where we were generating syntactically 
invalid SQL in some exclude() queries.

Backport of r9588 from trunk.


Modified: django/branches/releases/1.0.X/django/db/models/sql/query.py
===================================================================
--- django/branches/releases/1.0.X/django/db/models/sql/query.py        
2008-12-07 05:48:01 UTC (rev 9588)
+++ django/branches/releases/1.0.X/django/db/models/sql/query.py        
2008-12-07 05:50:26 UTC (rev 9589)
@@ -1695,7 +1695,6 @@
         alias = self.get_initial_alias()
         field, col, opts, joins, last, extra = self.setup_joins(
                 start.split(LOOKUP_SEP), opts, alias, False)
-        self.unref_alias(alias)
         alias = joins[last[-1]]
         self.select = [(alias, self.alias_map[alias][RHS_JOIN_COL])]
         self.select_fields = [field]

Modified: django/branches/releases/1.0.X/tests/regressiontests/queries/models.py
===================================================================
--- django/branches/releases/1.0.X/tests/regressiontests/queries/models.py      
2008-12-07 05:48:01 UTC (rev 9588)
+++ django/branches/releases/1.0.X/tests/regressiontests/queries/models.py      
2008-12-07 05:50:26 UTC (rev 9589)
@@ -227,6 +227,17 @@
     def __unicode__(self):
         return self.name
 
+# A simpler shared-foreign-key setup that can expose some problems.
+class SharedConnection(models.Model):
+    data = models.CharField(max_length=10)
+
+class PointerA(models.Model):
+    connection = models.ForeignKey(SharedConnection)
+
+class PointerB(models.Model):
+    connection = models.ForeignKey(SharedConnection)
+
+
 __test__ = {'API_TESTS':"""
 >>> t1 = Tag.objects.create(name='t1')
 >>> t2 = Tag.objects.create(name='t2', parent=t1)
@@ -986,6 +997,14 @@
 >>> qs = Author.objects.order_by().order_by('name')
 >>> 'ORDER BY' in qs.query.as_sql()[0]
 True
+
+Bug #9188 -- incorrect SQL was being generated for certain types of
+exclude() queries that crossed multi-valued relations.
+
+>>> PointerA.objects.filter(connection__pointerb__id=1)
+[]
+>>> PointerA.objects.exclude(connection__pointerb__id=1)
+[]
 """}
 
 # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__


--~--~---------~--~----~------------~-------~--~----~
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