From e66896226a41eb9e56b08d7adf29b44c0cd87dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20C=2E=20Leit=C3=A3o?= Date: Fri, 13 Jun 2014 10:12:31 +0200 Subject: [PATCH] Fixed #22826 -- Improved internal usage of Query.setup_joins. --- django/db/models/sql/expressions.py | 6 +++--- django/db/models/sql/query.py | 9 ++++----- django/db/models/sql/subqueries.py | 5 ++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/django/db/models/sql/expressions.py b/django/db/models/sql/expressions.py index 70646cfc619..e15cc2642c9 100644 --- a/django/db/models/sql/expressions.py +++ b/django/db/models/sql/expressions.py @@ -57,9 +57,9 @@ class SQLEvaluator(object): self.cols.append((node, query.aggregate_select[node.name])) else: try: - field, sources, opts, join_list, path = query.setup_joins( - field_list, query.get_meta(), - query.get_initial_alias(), self.reuse) + _, sources, _, join_list, path = query.setup_joins( + field_list, query.get_meta(), query.get_initial_alias(), + can_reuse=self.reuse) self._used_joins = join_list targets, _, join_list = query.trim_joins(sources, join_list, path) if self.reuse is not None: diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 6421f38796a..292322b9cb2 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -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)) diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index cfda1f552c8..5becdacd76e 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -215,7 +215,7 @@ class DateQuery(Query): Converts the query into an extraction query. """ try: - result = self.setup_joins( + field, _, _, joins, _ = self.setup_joins( field_name.split(LOOKUP_SEP), self.get_meta(), self.get_initial_alias(), @@ -224,9 +224,8 @@ class DateQuery(Query): raise FieldDoesNotExist("%s has no field named '%s'" % ( self.get_meta().object_name, field_name )) - field = result[0] self._check_field(field) # overridden in DateTimeQuery - alias = result[3][-1] + alias = joins[-1] select = self._get_select((alias, field.column), lookup_type) self.clear_select_clause() self.select = [SelectInfo(select, None)]