summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-12-01 00:43:39 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-12-02 07:23:33 +0100
commite5a92d400acb4ca6a8e1375d1ab8121f2c7220be (patch)
tree288bbfaafb587ea31f752c0ea955d695e9edcd47 /django/db/models/sql/query.py
parente3bde71676a704e27d62e5f96dd967f7305db7f2 (diff)
Fixed #33282 -- Fixed a crash when OR'ing subquery and aggregation lookups.
As a QuerySet resolves to Query the outer column references grouping logic should be defined on the latter and proxied from Subquery for the cases where get_group_by_cols is called on unresolved expressions. Thanks Antonio Terceiro for the report and initial patch.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index faca57da56..96f25830f0 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1053,6 +1053,14 @@ class Query(BaseExpression):
if col.alias in self.external_aliases
]
+ def get_group_by_cols(self, alias=None):
+ if alias:
+ return [Ref(alias, self)]
+ external_cols = self.get_external_cols()
+ if any(col.possibly_multivalued for col in external_cols):
+ return [self]
+ return external_cols
+
def as_sql(self, compiler, connection):
# Some backends (e.g. Oracle) raise an error when a subquery contains
# unnecessary ORDER BY clause.