1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #34803 -- Fixed queryset crash when filtering againts deeply nested OuterRef annotations.

Thanks Pierre-Nicolas Rigal for the report.

Regression in c67ea79aa9.
This commit is contained in:
willzhao
2023-08-31 07:51:44 +00:00
committed by Mariusz Felisiak
parent 9c68792843
commit 9cc0d7f7f8
5 changed files with 39 additions and 0 deletions

View File

@@ -870,6 +870,36 @@ class BasicExpressionsTests(TestCase):
).filter(ceo_company__isnull=False)
self.assertEqual(qs.get().ceo_company, "Test GmbH")
def test_annotation_with_deeply_nested_outerref(self):
bob = Employee.objects.create(firstname="Bob", based_in_eu=True)
self.max.manager = Manager.objects.create(name="Rock", secretary=bob)
self.max.save()
qs = Employee.objects.filter(
Exists(
Manager.objects.filter(
Exists(
Employee.objects.filter(
pk=OuterRef("secretary__pk"),
)
.annotate(
secretary_based_in_eu=OuterRef(OuterRef("based_in_eu"))
)
.filter(
Exists(
Company.objects.filter(
# Inner OuterRef refers to an outer
# OuterRef (not ResolvedOuterRef).
based_in_eu=OuterRef("secretary_based_in_eu")
)
)
)
),
secretary__pk=OuterRef("pk"),
)
)
)
self.assertEqual(qs.get(), bob)
def test_pickle_expression(self):
expr = Value(1)
expr.convert_value # populate cached property