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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user