summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-17 22:38:36 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-08-17 22:38:36 +0000
commit556fbc78a636d2be5c66a4393361476a6de091bc (patch)
tree44f5b10671e5eb9a1691545daaa7e18df88aa9ca /django/db/models/sql/query.py
parentb25d759bed2d72982cf12f59c38dc3438e330da1 (diff)
Fixed #8039 -- Make sure that extra(tables=...) tables are always included in
the resulting SQL. Previously, an optimisation was removing them in some corner cases. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8429 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 2548d63100..8cf3f58105 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -542,7 +542,10 @@ class Query(object):
first = False
for t in self.extra_tables:
alias, unused = self.table_alias(t)
- if alias not in self.alias_map:
+ # Only add the alias if it's not already present (the table_alias()
+ # calls increments the refcount, so an alias refcount of one means
+ # this is the only reference.
+ if alias not in self.alias_map or self.alias_refcount[alias] == 1:
connector = not first and ', ' or ''
result.append('%s%s' % (connector, qn(alias)))
first = False