diff options
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 15 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 18 |
2 files changed, 13 insertions, 20 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index ddbcb0eb9a..a65c6e2596 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -521,8 +521,7 @@ class SQLCompiler: if grouping: if distinct_fields: raise NotImplementedError('annotate() + distinct(fields) is not implemented.') - if not order_by: - order_by = self.connection.ops.force_no_ordering() + order_by = order_by or self.connection.ops.force_no_ordering() result.append('GROUP BY %s' % ', '.join(grouping)) if having: @@ -588,8 +587,7 @@ class SQLCompiler: if opts is None: opts = self.query.get_meta() only_load = self.deferred_to_columns() - if not start_alias: - start_alias = self.query.get_initial_alias() + start_alias = start_alias or self.query.get_initial_alias() # The 'seen_models' is used to optimize checking the needed parent # alias for a given field. This also includes None -> start_alias to # be used by local fields. @@ -657,8 +655,7 @@ class SQLCompiler: # of the field is specified. if field.is_relation and opts.ordering and getattr(field, 'attname', None) != name: # Firstly, avoid infinite loops. - if not already_seen: - already_seen = set() + already_seen = already_seen or set() join_tuple = tuple(getattr(self.query.alias_map[j], 'join_cols', None) for j in joins) if join_tuple in already_seen: raise FieldError('Infinite loop caused by ordering.') @@ -680,8 +677,7 @@ class SQLCompiler: same input, as the prefixes of get_ordering() and get_distinct() must match. Executing SQL where this is not true is an error. """ - if not alias: - alias = self.query.get_initial_alias() + alias = alias or self.query.get_initial_alias() field, targets, opts, joins, path = self.query.setup_joins( pieces, opts, alias) alias = joins[-1] @@ -1037,8 +1033,7 @@ class SQLCompiler: is needed, as the filters describe an empty set. In that case, None is returned, to avoid any unnecessary database interaction. """ - if not result_type: - result_type = NO_RESULTS + result_type = result_type or NO_RESULTS try: sql, params = self.as_sql() if not sql: diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index bfee2256e6..e657594c86 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -805,9 +805,9 @@ class Query: if isinstance(self.group_by, tuple): self.group_by = tuple([col.relabeled_clone(change_map) for col in self.group_by]) self.select = tuple([col.relabeled_clone(change_map) for col in self.select]) - if self._annotations: - self._annotations = OrderedDict( - (key, col.relabeled_clone(change_map)) for key, col in self._annotations.items()) + self._annotations = self._annotations and OrderedDict( + (key, col.relabeled_clone(change_map)) for key, col in self._annotations.items() + ) # 2. Rename the alias in the internal table/alias datastructures. for old_alias, new_alias in change_map.items(): @@ -1061,9 +1061,7 @@ class Query: and get_transform(). """ # __exact is the default lookup if one isn't given. - if not lookups: - lookups = ['exact'] - + lookups = lookups or ['exact'] for name in lookups[:-1]: lhs = self.try_transform(lhs, name) # First try get_lookup() so that the lookup takes precedence if the lhs @@ -2050,10 +2048,10 @@ class Query: # used. The proper fix would be to defer all decisions where # is_nullable() is needed to the compiler stage, but that is not easy # to do currently. - if connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls and field.empty_strings_allowed: - return True - else: - return field.null + return ( + connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls and + field.empty_strings_allowed + ) or field.null def get_order_dir(field, default='ASC'): |
