diff options
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 6421f38796..ff86e8b45b 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -664,16 +664,16 @@ class Query(object): If 'create' is true, a new alias is always created. Otherwise, the most recently created alias for the table (if one exists) is reused. """ - current = self.table_map.get(table_name) - if not create and current: - alias = current[0] + alias_list = self.table_map.get(table_name) + if not create and alias_list: + alias = alias_list[0] self.alias_refcount[alias] += 1 return alias, False # Create a new alias for this table. - if current: + if alias_list: alias = '%s%d' % (self.alias_prefix, len(self.alias_map) + 1) - current.append(alias) + alias_list.append(alias) else: # The first occurrence of a table uses the table name directly. alias = table_name @@ -900,7 +900,7 @@ class Query(object): return alias # No reuse is possible, so we need a new alias. - alias, _ = self.table_alias(table, True) + alias, _ = self.table_alias(table, create=True) if not lhs: # Not all tables need to be joined to anything. No join type # means the later columns are ignored. @@ -1008,7 +1008,7 @@ class Query(object): # Join promotion note - we must not remove any rows here, so use # outer join if there isn't any existing join. - field, sources, opts, join_list, path = self.setup_joins( + _, sources, opts, join_list, path = self.setup_joins( field_list, opts, self.get_initial_alias()) # Process the join chain to see if it can be trimmed @@ -1158,7 +1158,7 @@ class Query(object): try: field, sources, opts, join_list, path = self.setup_joins( - parts, opts, alias, can_reuse, allow_many) + parts, opts, alias, can_reuse=can_reuse, allow_many=allow_many) # split_exclude() needs to know which joins were generated for the # lookup parts self._lookup_joins = join_list @@ -1605,9 +1605,8 @@ class Query(object): for name in field_names: # Join promotion note - we must not remove any rows here, so # if there is no existing joins, use outer join. - field, targets, u2, joins, path = self.setup_joins( - name.split(LOOKUP_SEP), opts, alias, can_reuse=None, - allow_many=allow_m2m) + _, targets, _, joins, path = self.setup_joins( + name.split(LOOKUP_SEP), opts, alias, allow_many=allow_m2m) targets, final_alias, joins = self.trim_joins(targets, joins, path) for target in targets: self.select.append(SelectInfo((final_alias, target.column), target)) |
