Permalink
Browse files

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...
1 parent e8707e0 commit d4f0ae42a2ed4894b3eccb613df0d75e582330a6 @malcolmt malcolmt committed Dec 7, 2008
Showing with 19 additions and 1 deletion.
  1. +0 −1 django/db/models/sql/query.py
  2. +19 −0 tests/regressiontests/queries/models.py
@@ -1695,7 +1695,6 @@ def set_start(self, start):
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]
@@ -227,6 +227,17 @@ class ReservedName(models.Model):
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 @@ def __unicode__(self):
>>> 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__

1 comment on commit d4f0ae4

neyer commented on d4f0ae4 Jan 26, 2016

If you are writing django code yourself, and are seeing this same error, wondering why it shows up if it's been fixed:

I got here today. Are you using an interactive python prompt, and doing a 'reload' on a module where you defined models? That's what got me here. The warnning you see in the prompt ("don't reload the models.py file, it can break things") - this is one of the things that breaks.

You can fix the problem just by exiting the REPL and starting a new one.

Please sign in to comment.