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

Fixed #36405 -- Fixed Aggregate.order_by using OuterRef.

co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
Adam Johnson
2025-05-21 13:48:59 +01:00
committed by Sarah Boyce
parent b8e5a8a9a2
commit c2615a0500
4 changed files with 45 additions and 5 deletions

View File

@@ -2413,6 +2413,35 @@ class AggregateTestCase(TestCase):
}
self.assertEqual(values, expected_values)
@skipUnlessDBFeature("supports_aggregate_order_by_clause")
def test_string_agg_filter_outerref(self):
values = (
Publisher.objects.annotate(
stringagg=Subquery(
Book.objects.annotate(
stringagg=StringAgg(
"name",
delimiter=Value(";"),
order_by=OuterRef("num_awards"),
)
).values("stringagg")[:1]
)
)
.values("stringagg")
.order_by("id")
)
self.assertQuerySetEqual(
values,
[
{
"stringagg": "The Definitive Guide to Django: "
"Web Development Done Right"
}
]
* 5,
)
@skipUnlessDBFeature("supports_json_field", "supports_aggregate_order_by_clause")
def test_string_agg_jsonfield_order_by(self):
Employee.objects.bulk_create(