mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #31916 -- Fixed combined queryset crash when combining with ordered combined querysets.
This commit is contained in:
@@ -359,7 +359,7 @@ class SQLCompiler:
|
|||||||
|
|
||||||
for expr, is_ref in order_by:
|
for expr, is_ref in order_by:
|
||||||
resolved = expr.resolve_expression(self.query, allow_joins=True, reuse=None)
|
resolved = expr.resolve_expression(self.query, allow_joins=True, reuse=None)
|
||||||
if self.query.combinator:
|
if self.query.combinator and self.select:
|
||||||
src = resolved.get_source_expressions()[0]
|
src = resolved.get_source_expressions()[0]
|
||||||
expr_src = expr.get_source_expressions()[0]
|
expr_src = expr.get_source_expressions()[0]
|
||||||
# Relabel order by columns to raw numbers if this is a combined
|
# Relabel order by columns to raw numbers if this is a combined
|
||||||
|
|||||||
@@ -237,12 +237,15 @@ class QuerySetSetOperationTests(TestCase):
|
|||||||
def test_unsupported_ordering_slicing_raises_db_error(self):
|
def test_unsupported_ordering_slicing_raises_db_error(self):
|
||||||
qs1 = Number.objects.all()
|
qs1 = Number.objects.all()
|
||||||
qs2 = Number.objects.all()
|
qs2 = Number.objects.all()
|
||||||
|
qs3 = Number.objects.all()
|
||||||
msg = 'LIMIT/OFFSET not allowed in subqueries of compound statements'
|
msg = 'LIMIT/OFFSET not allowed in subqueries of compound statements'
|
||||||
with self.assertRaisesMessage(DatabaseError, msg):
|
with self.assertRaisesMessage(DatabaseError, msg):
|
||||||
list(qs1.union(qs2[:10]))
|
list(qs1.union(qs2[:10]))
|
||||||
msg = 'ORDER BY not allowed in subqueries of compound statements'
|
msg = 'ORDER BY not allowed in subqueries of compound statements'
|
||||||
with self.assertRaisesMessage(DatabaseError, msg):
|
with self.assertRaisesMessage(DatabaseError, msg):
|
||||||
list(qs1.order_by('id').union(qs2))
|
list(qs1.order_by('id').union(qs2))
|
||||||
|
with self.assertRaisesMessage(DatabaseError, msg):
|
||||||
|
list(qs1.union(qs2).order_by('id').union(qs3))
|
||||||
|
|
||||||
@skipIfDBFeature('supports_select_intersection')
|
@skipIfDBFeature('supports_select_intersection')
|
||||||
def test_unsupported_intersection_raises_db_error(self):
|
def test_unsupported_intersection_raises_db_error(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user