summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiddus <dcsid10@gmail.com>2026-04-13 11:32:43 -0400
committerJacob Walls <jacobtylerwalls@gmail.com>2026-05-11 14:50:40 -0400
commit9c655e98006dec4f4fd47a84c254f36404d631e4 (patch)
tree907fd592cd83885638404211860fd1517ad097ca
parentcb192dbb191525550f90d7cb9cff756f57e86aec (diff)
Fixed #36938 -- Removed unnecessary ordering from compound queries.
-rw-r--r--django/db/backends/oracle/features.py3
-rw-r--r--django/db/models/sql/compiler.py9
2 files changed, 9 insertions, 3 deletions
diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py
index 55c64a818d..81bb28ea2a 100644
--- a/django/db/backends/oracle/features.py
+++ b/django/db/backends/oracle/features.py
@@ -86,9 +86,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"annotations.tests.NonAggregateAnnotationTestCase.test_custom_functions",
"annotations.tests.NonAggregateAnnotationTestCase."
"test_custom_functions_can_ref_other_functions",
- # A bug in Django with respect to unioning ordered querysets (#36938).
- "queries.test_qs_combinators.QuerySetSetOperationTests."
- "test_count_union_with_select_related_in_values",
}
insert_test_table_with_defaults = (
"INSERT INTO {} VALUES (DEFAULT, DEFAULT, DEFAULT)"
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index bcf28f9ae1..6442ed7ecb 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -640,6 +640,15 @@ class SQLCompiler:
if selected is not None and compiler.query.selected is None:
compiler.query = compiler.query.clone()
compiler.query.set_values(selected)
+ if (
+ (
+ features.requires_compound_order_by_subquery
+ and not features.ignores_unnecessary_order_by_in_subqueries
+ )
+ or not features.supports_parentheses_in_compound
+ ) and compiler.get_order_by():
+ compiler.query = compiler.query.clone()
+ compiler.query.clear_ordering(force=False)
part_sql, part_args = compiler.as_sql(with_col_aliases=True)
if compiler.query.combinator:
# Wrap in a subquery if wrapping in parentheses isn't