summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-05-04 23:42:52 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-05 11:41:35 +0200
commit136ff592ad8aa8b7fa1e61435e5501cc98ce8573 (patch)
tree4d6ae1f178a5d9da39bd293fafa9ad153e2d49c7 /django
parent06fd4df41afb5aa1d681b853c3c08d8c688ca3a5 (diff)
Fixed #32690 -- Fixed __in lookup crash when combining with filtered aggregates.
Having lookups group by subquery right-hand-sides is likely unnecessary in the first place but relatively large amount of work would be needed to achieve that such as making Lookup instances proper resolvable expressions. Regression in 35431298226165986ad07e91f9d3aca721ff38ec. Thanks James A. Munsch for the report.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/lookups.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index 5089737034..8d3648b393 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -406,6 +406,15 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
self.rhs.add_fields(['pk'])
return super().process_rhs(compiler, connection)
+ def get_group_by_cols(self, alias=None):
+ cols = self.lhs.get_group_by_cols()
+ if hasattr(self.rhs, 'get_group_by_cols'):
+ if not getattr(self.rhs, 'has_select_fields', True):
+ self.rhs.clear_select_clause()
+ self.rhs.add_fields(['pk'])
+ cols.extend(self.rhs.get_group_by_cols())
+ return cols
+
def get_rhs_op(self, connection, rhs):
return 'IN %s' % rhs