Django

Code

Changeset 7447

Show
Ignore:
Timestamp:
04/23/08 05:43:42 (3 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Fixed a crash when using extra(tables=...). Fixed #7045.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r7445 r7447  
    426426            if not self.alias_refcount[alias]: 
    427427                continue 
    428             name, alias, join_type, lhs, lhs_col, col, nullable = self.alias_map[alias] 
     428            try: 
     429                name, alias, join_type, lhs, lhs_col, col, nullable = self.alias_map[alias] 
     430            except KeyError: 
     431                # Extra tables can end up in self.tables, but not in the 
     432                # alias_map if they aren't in a join. That's OK. We skip them. 
     433                continue 
    429434            alias_str = (alias != name and ' %s' % alias or '') 
    430435            if join_type and not first: 
     
    437442            first = False 
    438443        for t in self.extra_tables: 
    439             alias, created = self.table_alias(t) 
    440             if created
     444            alias, unused = self.table_alias(t) 
     445            if alias not in self.alias_map
    441446                connector = not first and ', ' or '' 
    442                 result.append('%s%s' % (connector, alias)) 
     447                result.append('%s%s' % (connector, qn(alias))) 
    443448                first = False 
    444449        return result, [] 
  • django/branches/queryset-refactor/tests/regressiontests/queries/models.py

    r7440 r7447  
    635635... 
    636636IndexError: ... 
     637 
     638Bug #7045 -- extra tables used to crash SQL construction on the second use. 
     639>>> qs = Ranking.objects.extra(tables=['django_site']) 
     640>>> s = qs.query.as_sql() 
     641>>> s = qs.query.as_sql()   # test passes if this doesn't raise an exception. 
     642 
    637643"""} 
    638644