summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2022-09-07 22:30:06 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-09-08 05:50:02 +0200
commit32536b1324e98768dd892980408a8c6b26c23fd9 (patch)
tree2aacd612afe69bd4ed413b82d1e065ad21e230c8 /django/db/models/sql/compiler.py
parenta2e580acf62a3de4f9108cc1af061a02b94b1064 (diff)
downloaddjango-32536b1324e98768dd892980408a8c6b26c23fd9.tar.gz
Fixed #33992 -- Fixed queryset crash when aggregating over a group containing Exists.
A more in-depth solution is likely to make sure that we always GROUP BY selected annotations or revisit how we use Query.exists() in the Exists expression but that requires extra work that isn't suitable for a backport. Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be. Thanks Fernando Flores Villaça for the report.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 96d10b9eda..27310e5d9f 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -160,7 +160,10 @@ class SQLCompiler:
expressions = self.collapse_group_by(expressions, having_group_by)
for expr in expressions:
- sql, params = self.compile(expr)
+ try:
+ sql, params = self.compile(expr)
+ except EmptyResultSet:
+ continue
sql, params = expr.select_format(self, sql, params)
params_hash = make_hashable(params)
if (sql, params_hash) not in seen: