details: https://code.tryton.org/tryton/commit/9d74fae2b477
branch: 7.6
user: Cédric Krier <[email protected]>
date: Tue Jan 13 16:50:08 2026 +0100
description:
Ensure to always surround USING expression with parenthesis in CREATE
INDEX
Closes #14487
(grafted from b45a29b26853324f65adc8c49b59a62d6f591529)
diffstat:
trytond/trytond/backend/postgresql/table.py | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diffs (31 lines):
diff -r 2c9271b59fe2 -r 9d74fae2b477 trytond/trytond/backend/postgresql/table.py
--- a/trytond/trytond/backend/postgresql/table.py Wed Jan 14 00:35:13
2026 +0100
+++ b/trytond/trytond/backend/postgresql/table.py Tue Jan 13 16:50:08
2026 +0100
@@ -4,6 +4,7 @@
import re
from psycopg2.sql import SQL, Identifier
+from sql import Column
from sql.operators import NotEqual
from trytond.backend.table import (
@@ -626,11 +627,18 @@
@classmethod
def _get_expression_variables(cls, expression, usage):
variables = {
- 'expression': SQL(str(expression)),
'collate': SQL(''),
'opclass': SQL(''),
'order': SQL(''),
}
+ if isinstance(expression, Column):
+ variables['expression'] = SQL(str(expression))
+ else:
+ expression_str = str(expression)
+ if expression_str.startswith('(') and expression_str.endswith(')'):
+ variables['expression'] = SQL(expression)
+ else:
+ variables['expression'] = SQL(f'({expression})')
if usage.options.get('collation'):
variables['collate'] = SQL('COLLATE {}').format(
usage.options['collation'])