﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36938	Unioning an ordered queryset fails on Oracle unless a limit is taken	Jacob Walls	Sidharth Dusanapudi	"For the purposes of testing only, adjust this existing test to remove the limits on these unioned querysets:

{{{#!diff
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index d1d6bfcbe3..580e9c8734 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -680,8 +680,8 @@ class QuerySetSetOperationTests(TestCase):
 
     @skipUnlessDBFeature(""supports_slicing_ordering_in_compound"")
     def test_ordering_subqueries(self):
-        qs1 = Number.objects.order_by(""num"")[:2]
-        qs2 = Number.objects.order_by(""-num"")[:2]
+        qs1 = Number.objects.order_by(""num"")
+        qs2 = Number.objects.order_by(""-num"")
         self.assertNumbersEqual(qs1.union(qs2).order_by(""-num"")[:4], [9, 8, 1, 0])
 
     @skipIfDBFeature(""supports_slicing_ordering_in_compound"")

}}}

Running that test against Oracle produces:
{{{
oracledb.exceptions.DatabaseError: ORA-00907: missing right parenthesis
Help: https://docs.oracle.com/error-help/db/ora-00907/
}}}
For this SQL:
{{{#!sql
SELECT *
FROM (
        (SELECT ""QUERIES_NUMBER"".""ID"" AS ""COL1"",
                ""QUERIES_NUMBER"".""NUM"" AS ""COL2"",
                ""QUERIES_NUMBER"".""OTHER_NUM"" AS ""COL3"",
                ""QUERIES_NUMBER"".""ANOTHER_NUM"" AS ""COL4""
         FROM ""QUERIES_NUMBER""
         ORDER BY ""QUERIES_NUMBER"".""NUM"" ASC)
      UNION
        (SELECT ""QUERIES_NUMBER"".""ID"" AS ""COL1"",
                ""QUERIES_NUMBER"".""NUM"" AS ""COL2"",
                ""QUERIES_NUMBER"".""OTHER_NUM"" AS ""COL3"",
                ""QUERIES_NUMBER"".""ANOTHER_NUM"" AS ""COL4""
         FROM ""QUERIES_NUMBER""
         ORDER BY ""QUERIES_NUMBER"".""NUM"" DESC))
ORDER BY ""COL2"" DESC FETCH FIRST 4 ROWS ONLY;
}}}

----
Discovered after a test was merged that does the same thing, see https://github.com/django/django/pull/20662#issuecomment-3931102843. I'll open a PR to xfail that test (`test_count_union_with_select_related_in_values`) on Oracle for the time being."	Bug	assigned	Database layer (models, ORM)	6.0	Normal		oracle, union, order_by	Sidharth Dusanapudi	Accepted	1	0	0	1	0	0
