1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #28621 -- Fixed crash of annotations with nested OuterRef.

This commit is contained in:
Sergey Fedoseev 2020-07-01 14:01:46 +05:00 committed by GitHub
parent dbae6de01e
commit ed6b14d459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -584,6 +584,8 @@ class ResolvedOuterRef(F):
class OuterRef(F):
contains_aggregate = False
def resolve_expression(self, *args, **kwargs):
if isinstance(self.name, self.__class__):
return self.name

View File

@ -710,6 +710,22 @@ class BasicExpressionsTests(TestCase):
).get(pk=self.gmbh.pk)
self.assertEqual(gmbh_salary.max_ceo_salary_raise, 2332)
def test_annotation_with_nested_outerref(self):
self.gmbh.point_of_contact = Employee.objects.get(lastname='Meyer')
self.gmbh.save()
inner = Employee.objects.annotate(
outer_lastname=OuterRef(OuterRef('lastname')),
).filter(lastname__startswith=Left('outer_lastname', 1))
qs = Employee.objects.annotate(
ceo_company=Subquery(
Company.objects.filter(
point_of_contact__in=inner,
ceo__pk=OuterRef('pk'),
).values('name'),
),
).filter(ceo_company__isnull=False)
self.assertEqual(qs.get().ceo_company, 'Test GmbH')
def test_pickle_expression(self):
expr = Value(1, output_field=IntegerField())
expr.convert_value # populate cached property