Fixed #31251 -- Disabled grouping by OuterRef() annotation.

This commit is contained in:
Rohit 2020-02-25 01:02:15 +05:30 committed by Mariusz Felisiak
parent 5bf28ac2ed
commit 486786c4c4
2 changed files with 11 additions and 0 deletions

View File

@ -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):

View File

@ -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'))