Skip to content

Commit 541c4a8

Browse files
committed
[FIX] util/snippets: correctly quote table/column in query
One literal column was present which caused issues with uppercase named columns. Redo the quoting with better tools from psycopg2. upg-1180733 closes #17 Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
1 parent f80482b commit 541c4a8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/util/snippets.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from concurrent.futures import ProcessPoolExecutor
88

99
from lxml import etree, html
10+
from psycopg2 import sql
1011
from psycopg2.extensions import quote_ident
1112
from psycopg2.extras import Json
1213

@@ -64,19 +65,17 @@ def add_snippet_names_on_html_field(cr, table, column, snippets, regex):
6465
Will search for all the snippets in the fields mentionned (should be html fields) and add
6566
the corresponding data-snippet on them.
6667
"""
67-
68-
def quote(ident):
69-
return quote_ident(ident, cr._cnx)
70-
7168
query = cr.mogrify(
72-
f"""
73-
SELECT id, array((SELECT regexp_matches({quote(column)}, %(regex)s, 'g'))), {column}
74-
FROM {quote(table)}
75-
WHERE {quote(column)} ~ %(regex)s
76-
""",
69+
sql.SQL(
70+
"""
71+
SELECT id, array((SELECT regexp_matches({column}, %(regex)s, 'g'))), {column}
72+
FROM {table}
73+
WHERE {column} ~ %(regex)s
74+
"""
75+
).format(column=sql.Identifier(column), table=sql.Identifier(table)),
7776
{"regex": regex},
7877
).decode()
79-
where = cr.mogrify(f"{quote(column)} ~ %s", [regex]).decode()
78+
where = cr.mogrify(sql.SQL("{column} ~ %s").format(column=sql.Identifier(column)), [regex]).decode()
8079
ids_ranges = determine_chunk_limit_ids(cr, table, [column], where)
8180
for id0, id1 in ids_ranges:
8281
add_snippet_names(cr, table, column, snippets, query + f" AND id BETWEEN {id0} AND {id1}")

0 commit comments

Comments
 (0)