diff options
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/sql/compiler.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index f5222f21be..8b0fd1da46 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -157,7 +157,9 @@ class SQLCompiler: } expressions = [pk] + [ expr for expr in expressions - if expr in having or getattr(expr, 'alias', None) not in pk_aliases + if expr in having or ( + getattr(expr, 'alias', None) is not None and expr.alias not in pk_aliases + ) ] elif self.connection.features.allows_group_by_selected_pks: # Filter out all expressions associated with a table's primary key |
