summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py21
-rw-r--r--django/db/models/sql/query.py7
2 files changed, 11 insertions, 17 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index a65c6e2596..3080b8c3ee 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -114,13 +114,10 @@ class SQLCompiler:
for col in cols:
expressions.append(col)
for expr, (sql, params, is_ref) in order_by:
- if expr.contains_aggregate:
- continue
- # We can skip References to select clause, as all expressions in
- # the select clause are already part of the group by.
- if is_ref:
- continue
- expressions.extend(expr.get_source_expressions())
+ # Skip References to the select clause, as all expressions in the
+ # select clause are already part of the group by.
+ if not expr.contains_aggregate and not is_ref:
+ expressions.extend(expr.get_source_expressions())
having_group_by = self.having.get_group_by_cols() if self.having else ()
for expr in having_group_by:
expressions.append(expr)
@@ -283,7 +280,7 @@ class SQLCompiler:
continue
col, order = get_order_dir(field, asc)
- descending = True if order == 'DESC' else False
+ descending = order == 'DESC'
if col in self.query.annotation_select:
# Reference to expression in SELECT clause
@@ -646,7 +643,7 @@ class SQLCompiler:
The 'name' is of the form 'field1__field2__...__fieldN'.
"""
name, order = get_order_dir(name, default_order)
- descending = True if order == 'DESC' else False
+ descending = order == 'DESC'
pieces = name.split(LOOKUP_SEP)
field, targets, alias, joins, path, opts = self._setup_joins(pieces, opts, alias)
@@ -747,11 +744,9 @@ class SQLCompiler:
# included in the related selection.
fields_found = set()
if requested is None:
- if isinstance(self.query.select_related, dict):
+ restricted = isinstance(self.query.select_related, dict)
+ if restricted:
requested = self.query.select_related
- restricted = True
- else:
- restricted = False
def get_related_klass_infos(klass_info, related_klass_infos):
klass_info['related_klass_infos'] = related_klass_infos
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index e657594c86..9c97ed772d 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -666,10 +666,9 @@ class Query:
workset = {}
for model, values in seen.items():
for field in model._meta.local_fields:
- if field in values:
- continue
- m = field.model._meta.concrete_model
- add_to_dict(workset, m, field)
+ if field not in values:
+ m = field.model._meta.concrete_model
+ add_to_dict(workset, m, field)
for model, values in must_include.items():
# If we haven't included a model in workset, we don't add the
# corresponding must_include fields for that model, since an