Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

queryset-refactor: Fixed handling of extra(tables=...). In passing, t…

…his solves

a duplicate table / bad SQL problem. Refs #2496.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6678de130c9539d2103b5c72561c0869f0d838d7 1 parent 93b4199
Malcolm Tredinnick authored October 14, 2007
6  django/db/models/sql/query.py
@@ -371,7 +371,11 @@ def get_from_clause(self):
371 371
                             qn(lhs_col), qn(alias), qn(col)))
372 372
             else:
373 373
                 result.append('%s%s' % (qn(name), alias_str))
374  
-        result.extend(self.extra_tables)
  374
+        extra_tables = []
  375
+        for t in self.extra_tables:
  376
+            alias, created = self.table_alias(t)
  377
+            if created:
  378
+                result.append(', %s' % alias)
375 379
         return result, []
376 380
 
377 381
     def get_grouping(self):
4  tests/regressiontests/queries/models.py
@@ -202,5 +202,9 @@ def __unicode__(self):
202 202
 [<Author: a3>]
203 203
 >>> Tag.objects.filter(item__isnull=True)
204 204
 [<Tag: t5>]
  205
+
  206
+Bug #2496
  207
+>>> Item.objects.extra(tables=['queries_author']).select_related().order_by('name')[:1]
  208
+[<Item: four>]
205 209
 """}
206 210
 

0 notes on commit 6678de1

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