mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #28621 -- Fixed crash of annotations with nested OuterRef.
This commit is contained in:
parent
dbae6de01e
commit
ed6b14d459
@ -584,6 +584,8 @@ class ResolvedOuterRef(F):
|
|||||||
|
|
||||||
|
|
||||||
class OuterRef(F):
|
class OuterRef(F):
|
||||||
|
contains_aggregate = False
|
||||||
|
|
||||||
def resolve_expression(self, *args, **kwargs):
|
def resolve_expression(self, *args, **kwargs):
|
||||||
if isinstance(self.name, self.__class__):
|
if isinstance(self.name, self.__class__):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -710,6 +710,22 @@ class BasicExpressionsTests(TestCase):
|
|||||||
).get(pk=self.gmbh.pk)
|
).get(pk=self.gmbh.pk)
|
||||||
self.assertEqual(gmbh_salary.max_ceo_salary_raise, 2332)
|
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):
|
def test_pickle_expression(self):
|
||||||
expr = Value(1, output_field=IntegerField())
|
expr = Value(1, output_field=IntegerField())
|
||||||
expr.convert_value # populate cached property
|
expr.convert_value # populate cached property
|
||||||
|
Loading…
Reference in New Issue
Block a user