Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9188 -- Fixed a case where we were generating syntactically in…

…valid SQL in some exclude() queries.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9588 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d4f0ae42a2ed4894b3eccb613df0d75e582330a6 1 parent e8707e0
Malcolm Tredinnick authored December 07, 2008
1  django/db/models/sql/query.py
@@ -1695,7 +1695,6 @@ def set_start(self, start):
1695 1695
         alias = self.get_initial_alias()
1696 1696
         field, col, opts, joins, last, extra = self.setup_joins(
1697 1697
                 start.split(LOOKUP_SEP), opts, alias, False)
1698  
-        self.unref_alias(alias)
1699 1698
         alias = joins[last[-1]]
1700 1699
         self.select = [(alias, self.alias_map[alias][RHS_JOIN_COL])]
1701 1700
         self.select_fields = [field]
19  tests/regressiontests/queries/models.py
@@ -227,6 +227,17 @@ class ReservedName(models.Model):
227 227
     def __unicode__(self):
228 228
         return self.name
229 229
 
  230
+# A simpler shared-foreign-key setup that can expose some problems.
  231
+class SharedConnection(models.Model):
  232
+    data = models.CharField(max_length=10)
  233
+
  234
+class PointerA(models.Model):
  235
+    connection = models.ForeignKey(SharedConnection)
  236
+
  237
+class PointerB(models.Model):
  238
+    connection = models.ForeignKey(SharedConnection)
  239
+
  240
+
230 241
 __test__ = {'API_TESTS':"""
231 242
 >>> t1 = Tag.objects.create(name='t1')
232 243
 >>> t2 = Tag.objects.create(name='t2', parent=t1)
@@ -986,6 +997,14 @@ def __unicode__(self):
986 997
 >>> qs = Author.objects.order_by().order_by('name')
987 998
 >>> 'ORDER BY' in qs.query.as_sql()[0]
988 999
 True
  1000
+
  1001
+Bug #9188 -- incorrect SQL was being generated for certain types of
  1002
+exclude() queries that crossed multi-valued relations.
  1003
+
  1004
+>>> PointerA.objects.filter(connection__pointerb__id=1)
  1005
+[]
  1006
+>>> PointerA.objects.exclude(connection__pointerb__id=1)
  1007
+[]
989 1008
 """}
990 1009
 
991 1010
 # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__

0 notes on commit d4f0ae4

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