mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
queryset-refactor: Fixed a crash when using extra(tables=...). Fixed #7045.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
42dc3b9ba2
commit
19d6bc7acd
@ -425,7 +425,12 @@ class Query(object):
|
|||||||
for alias in self.tables:
|
for alias in self.tables:
|
||||||
if not self.alias_refcount[alias]:
|
if not self.alias_refcount[alias]:
|
||||||
continue
|
continue
|
||||||
name, alias, join_type, lhs, lhs_col, col, nullable = self.alias_map[alias]
|
try:
|
||||||
|
name, alias, join_type, lhs, lhs_col, col, nullable = self.alias_map[alias]
|
||||||
|
except KeyError:
|
||||||
|
# Extra tables can end up in self.tables, but not in the
|
||||||
|
# alias_map if they aren't in a join. That's OK. We skip them.
|
||||||
|
continue
|
||||||
alias_str = (alias != name and ' %s' % alias or '')
|
alias_str = (alias != name and ' %s' % alias or '')
|
||||||
if join_type and not first:
|
if join_type and not first:
|
||||||
result.append('%s %s%s ON (%s.%s = %s.%s)'
|
result.append('%s %s%s ON (%s.%s = %s.%s)'
|
||||||
@ -436,10 +441,10 @@ class Query(object):
|
|||||||
result.append('%s%s%s' % (connector, qn(name), alias_str))
|
result.append('%s%s%s' % (connector, qn(name), alias_str))
|
||||||
first = False
|
first = False
|
||||||
for t in self.extra_tables:
|
for t in self.extra_tables:
|
||||||
alias, created = self.table_alias(t)
|
alias, unused = self.table_alias(t)
|
||||||
if created:
|
if alias not in self.alias_map:
|
||||||
connector = not first and ', ' or ''
|
connector = not first and ', ' or ''
|
||||||
result.append('%s%s' % (connector, alias))
|
result.append('%s%s' % (connector, qn(alias)))
|
||||||
first = False
|
first = False
|
||||||
return result, []
|
return result, []
|
||||||
|
|
||||||
|
@ -634,5 +634,11 @@ True
|
|||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
IndexError: ...
|
IndexError: ...
|
||||||
|
|
||||||
|
Bug #7045 -- extra tables used to crash SQL construction on the second use.
|
||||||
|
>>> qs = Ranking.objects.extra(tables=['django_site'])
|
||||||
|
>>> s = qs.query.as_sql()
|
||||||
|
>>> s = qs.query.as_sql() # test passes if this doesn't raise an exception.
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user