Skip to content

Commit

Permalink
[IMP] rename_models: Avoid mogrify 'IndexError: tuple index out of ra…
Browse files Browse the repository at this point in the history
…nge' for % LIKE parameter
  • Loading branch information
rousseldenis committed Nov 28, 2022
1 parent f0b809f commit 62a8f33
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,18 +905,25 @@ def rename_models(cr, model_spec):
column = row[1]
if not column_exists(cr, table, column):
continue
query = """
UPDATE {table}
SET {column} = replace(
{column}, %(old)s, %(new)s)
WHERE {column} LIKE %(old_like)s
"""
sql_query = sql.SQL(query).format(
table=sql.Identifier(table),
column=sql.Identifier(column)
)
logged_query(
cr, """
UPDATE %(table)s
SET %(column)s = replace(
%(column)s, '%(old)s,', '%(new)s,')
WHERE %(column)s LIKE '%(old)s,%%'
""" % {
"table": table,
"column": column,
"old": old,
"new": new,
}, skip_no_result=True,
cr,
sql_query,
{
"old": old + ',',
"old_like": old + ',%%',
"new": new + ',',
},
skip_no_result=True,
)
# Update export profiles references
logged_query(
Expand Down

0 comments on commit 62a8f33

Please sign in to comment.