From d7b2aa24f75434c2ce50100cfef3586071e0747a Mon Sep 17 00:00:00 2001 From: Дилян Палаузов Date: Wed, 3 Jan 2018 18:52:12 -0500 Subject: Fixed #28982 -- Simplified code with and/or. --- django/db/models/sql/query.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'django/db/models/sql/query.py') 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'): -- cgit v1.3