Skip to content

Commit

Permalink
[FIX] _convert_field_bootstrap_4to5_sql: convert parameters
Browse files Browse the repository at this point in the history
- Fix update query
- Avoid templating the sql directly from the method parameters.
  • Loading branch information
chienandalu committed Nov 13, 2023
1 parent 69f155a commit 626dd0e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,21 +385,23 @@ 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)
params = ()
sql = "SELECT id, %s FROM %s "
params = (AsIs(field), AsIs(table))
if ids:
sql += "WHERE id IN %s"
params = (tuple(ids),)
params = params + (tuple(ids),)
cr.execute(sql, 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_,
(
AsIs(table),
AsIs(field),
new_content,
id_,
),
)


Expand Down

0 comments on commit 626dd0e

Please sign in to comment.