mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +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:
committed by
Sarah Boyce
parent
5ae9922666
commit
602fe961e6
@@ -1999,6 +1999,21 @@ class PrefetchLimitTests(TestDataMixin, TestCase):
|
||||
with self.assertRaisesMessage(NotSupportedError, msg):
|
||||
list(Book.objects.prefetch_related(Prefetch("authors", authors[1:])))
|
||||
|
||||
@skipUnlessDBFeature("supports_over_clause")
|
||||
def test_empty_order(self):
|
||||
authors = Author.objects.order_by()
|
||||
with self.assertNumQueries(3):
|
||||
books = list(
|
||||
Book.objects.prefetch_related(
|
||||
Prefetch("authors", authors),
|
||||
Prefetch("authors", authors[:1], to_attr="authors_sliced"),
|
||||
)
|
||||
)
|
||||
for book in books:
|
||||
with self.subTest(book=book):
|
||||
self.assertEqual(len(book.authors_sliced), 1)
|
||||
self.assertIn(book.authors_sliced[0], list(book.authors.all()))
|
||||
|
||||
|
||||
class DeprecationTests(TestCase):
|
||||
def test_get_current_queryset_warning(self):
|
||||
|
||||
Reference in New Issue
Block a user