Skip to content

Commit

Permalink
Merge pull request #353 from Tecnativa/openupgrade_160-fix-_convert_f…
Browse files Browse the repository at this point in the history
…ield_bootstrap_4to5_sql

[FIX] _convert_field_bootstrap_4to5_sql: convert parameters
  • Loading branch information
pedrobaeza authored Nov 13, 2023
2 parents 69f155a + 3c51df0 commit 1fffdea
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
from itertools import product

from psycopg2.extensions import AsIs
from psycopg2 import sql

from odoo.tools.translate import _get_translation_upgrade_queries

Expand Down Expand Up @@ -385,21 +385,24 @@ def _convert_field_bootstrap_4to5_sql(cr, table, field, ids=None):
:param list ids:
List of IDs, to restrict operation to them.
"""
sql = "SELECT id, %s FROM %s " % (field, table)
query = "SELECT id, {field} FROM {table}"
format_query_args = {"field": sql.Identifier(field), "table": sql.Identifier(table)}
params = ()
if ids:
sql += "WHERE id IN %s"
query = f"{query} WHERE id IN %s"
params = (tuple(ids),)
cr.execute(sql, params)
cr.execute(sql.SQL(query).format(**format_query_args), params)
for id_, old_content in cr.fetchall():
new_content = convert_string_bootstrap_4to5(old_content)
if old_content != new_content:
cr.execute(
"UPDATE %s SET %s = %s WHERE id = %s",
AsIs(table),
AsIs(field),
new_content,
id_,
sql.SQL("UPDATE {table} SET {field} = %s WHERE id = %s").format(
**format_query_args
),
(
new_content,
id_,
),
)


Expand Down

0 comments on commit 1fffdea

Please sign in to comment.