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

Fixed #35972 -- Fixed lookup crashes after subquery annotations.

This commit is contained in:
Jacob Walls
2024-12-29 01:13:48 -08:00
committed by Sarah Boyce
parent 079d31e698
commit 8914f4703c
11 changed files with 128 additions and 23 deletions

View File

@@ -749,6 +749,24 @@ class BasicExpressionsTests(TestCase):
)
self.assertCountEqual(subquery_test2, [self.foobar_ltd])
def test_lookups_subquery(self):
smallest_company = Company.objects.order_by("num_employees").values("name")[:1]
for lookup in CharField.get_lookups():
if lookup == "isnull":
continue # not allowed, rhs must be a literal boolean.
if (
lookup == "in"
and not connection.features.allow_sliced_subqueries_with_in
):
continue
if lookup == "range":
rhs = (Subquery(smallest_company), Subquery(smallest_company))
else:
rhs = Subquery(smallest_company)
with self.subTest(lookup=lookup):
qs = Company.objects.filter(**{f"name__{lookup}": rhs})
self.assertGreater(len(qs), 0)
def test_uuid_pk_subquery(self):
u = UUIDPK.objects.create()
UUID.objects.create(uuid_fk=u)