Skip to content

Commit 78212ce

Browse files
committed
[IMP] convert_binary_field_to_attachment: use format_query
Be safe and correctly quote identifiers. Part-of: #42
1 parent 725955a commit 78212ce

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/util/fields.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import warnings
77

88
import psycopg2
9+
from psycopg2 import sql
910

1011
try:
1112
from odoo import release
@@ -38,6 +39,7 @@ def make_index_name(table_name, column_name):
3839
column_exists,
3940
column_type,
4041
explode_query_range,
42+
format_query,
4143
get_value_or_en_translation,
4244
parallel_execute,
4345
pg_text2html,
@@ -672,7 +674,15 @@ def convert_binary_field_to_attachment(cr, model, field, encoded=True, name_fiel
672674
A = env(cr)["ir.attachment"]
673675
iter_cur = cr._cnx.cursor("fetch_binary")
674676
iter_cur.itersize = 1
675-
iter_cur.execute('SELECT id, "{field}", {name_query} FROM {table} WHERE "{field}" IS NOT NULL'.format(**locals()))
677+
iter_cur.execute(
678+
format_query(
679+
cr,
680+
"SELECT id, {field}, {name_query} FROM {table} WHERE {field} IS NOT NULL",
681+
field=field,
682+
name_query=sql.SQL(name_query),
683+
table=table,
684+
)
685+
)
676686
for rid, data, name in iter_cur:
677687
# we can't save create the attachment with res_model & res_id as it will fail computing
678688
# `res_name` field for non-loaded models. Store it naked and change it via SQL after.

0 commit comments

Comments
 (0)