mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #35665 -- Fixed a crash when passing an empty order_by to Window.
This also caused un-ordered sliced prefetches to crash as they rely on Window.
Regression in e16d0c176e
that made OrderByList
piggy-back ExpressionList without porting the empty handling that the latter
provided.
Supporting explicit empty ordering on Window functions and slicing is arguably
a foot-gun design due to how backends will return undeterministic results but
this is a problem that requires a larger discussion.
Refs #35064.
Thanks Andrew Backer for the report and Mariusz for the review.
This commit is contained in:
parent
5ae9922666
commit
602fe961e6
6 changed files with 38 additions and 13 deletions
|
@ -928,6 +928,20 @@ class WindowFunctionTests(TestCase):
|
|||
),
|
||||
)
|
||||
|
||||
def test_empty_ordering(self):
|
||||
"""
|
||||
Explicit empty ordering makes little sense but it is something that
|
||||
was historically allowed.
|
||||
"""
|
||||
qs = Employee.objects.annotate(
|
||||
sum=Window(
|
||||
expression=Sum("salary"),
|
||||
partition_by="department",
|
||||
order_by=[],
|
||||
)
|
||||
).order_by("department", "sum")
|
||||
self.assertEqual(len(qs), 12)
|
||||
|
||||
def test_related_ordering_with_count(self):
|
||||
qs = Employee.objects.annotate(
|
||||
department_sum=Window(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue