Skip to content

Commit e71c62b

Browse files
committed
Workaround for multiple union with MariaDB 10.3.
See https://code.djangoproject.com/ticket/31445 for details; we need to not create nested brackets as that is not understood, but do need each part to be in brackets because my use of annotate/order_by is causing the subqueries to have ORDER BY which does not work without brackets.
1 parent c769f65 commit e71c62b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

django/db/models/sql/compiler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ def get_combinator_sql(self, combinator, all):
432432
*self.query.annotation_select,
433433
))
434434
part_sql, part_args = compiler.as_sql()
435+
if combinator == 'union' and not compiler.query.combinator:
436+
part_sql = '({})'.format(part_sql)
435437
if compiler.query.combinator:
436438
# Wrap in a subquery if wrapping in parentheses isn't
437439
# supported.
@@ -453,7 +455,7 @@ def get_combinator_sql(self, combinator, all):
453455
combinator_sql = self.connection.ops.set_operators[combinator]
454456
if all and combinator == 'union':
455457
combinator_sql += ' ALL'
456-
braces = '({})' if features.supports_slicing_ordering_in_compound else '{}'
458+
braces = '({})' if features.supports_slicing_ordering_in_compound and combinator != 'union' else '{}'
457459
sql_parts, args_parts = zip(*((braces.format(sql), args) for sql, args in parts))
458460
result = [' {} '.format(combinator_sql).join(sql_parts)]
459461
params = []

0 commit comments

Comments
 (0)