From 486786c4c480f5b1ae3ac1c95858b03699b9eb9c Mon Sep 17 00:00:00 2001 From: Rohit Date: Tue, 25 Feb 2020 01:02:15 +0530 Subject: [PATCH] Fixed #31251 -- Disabled grouping by OuterRef() annotation. --- django/db/models/expressions.py | 3 +++ tests/expressions/tests.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 2e831b21ac..a165923784 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -562,6 +562,9 @@ class ResolvedOuterRef(F): def relabeled_clone(self, relabels): return self + def get_group_by_cols(self, alias=None): + return [] + class OuterRef(F): def resolve_expression(self, *args, **kwargs): diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 5e60c379a9..da6e04e8fd 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -687,6 +687,14 @@ class BasicExpressionsTests(TestCase): [self.foobar_ltd.ceo], ) + def test_subquery_group_by_outerref_in_filter(self): + inner = Company.objects.annotate( + employee=OuterRef('pk'), + ).values('employee').annotate( + min_num_chairs=Min('num_chairs'), + ).values('ceo') + self.assertIs(Employee.objects.filter(pk__in=Subquery(inner)).exists(), True) + def test_case_in_filter_if_boolean_output_field(self): is_ceo = Company.objects.filter(ceo=OuterRef('pk')) is_poc = Company.objects.filter(point_of_contact=OuterRef('pk'))