Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] _convert_field_bootstrap_4to5_sql: convert parameters #353

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading