diff options
| author | Simon Charette <charette.s@gmail.com> | 2024-08-09 08:43:20 -0400 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-08-13 11:28:03 +0200 |
| commit | df236b0bcbbf1f54dfe6acc7761cd81b76ebf2cc (patch) | |
| tree | cef9184d9269ffcbe22d4f9c1afe81b186b91b41 /django | |
| parent | dbca05698a14d6c771346d3fe6b72159cb32ce14 (diff) | |
[5.1.x] 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 e16d0c176e9b89628cdec5e58c418378c4a2436a 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.
Backport of 602fe961e6834d665f2359087a1272e9f9806b71 from main.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/oracle/features.py | 1 | ||||
| -rw-r--r-- | django/db/models/expressions.py | 12 |
2 files changed, 6 insertions, 7 deletions
diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index a83560b892..72c6180f50 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -116,6 +116,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): "Oracle requires ORDER BY in row_number, ANSI:SQL doesn't.": { "expressions_window.tests.WindowFunctionTests." "test_row_number_no_ordering", + "prefetch_related.tests.PrefetchLimitTests.test_empty_order", }, "Oracle doesn't support changing collations on indexed columns (#33671).": { "migrations.test_operations.OperationTests." diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 0f5e68b0d4..c24c585658 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1377,16 +1377,14 @@ class ExpressionList(Func): template = "%(expressions)s" - def __init__(self, *expressions, **extra): - if not expressions: - raise ValueError( - "%s requires at least one expression." % self.__class__.__name__ - ) - super().__init__(*expressions, **extra) - def __str__(self): return self.arg_joiner.join(str(arg) for arg in self.source_expressions) + def as_sql(self, *args, **kwargs): + if not self.source_expressions: + return "", () + return super().as_sql(*args, **kwargs) + def as_sqlite(self, compiler, connection, **extra_context): # Casting to numeric is unnecessary. return self.as_sql(compiler, connection, **extra_context) |
