Skip to content

Commit

Permalink
Merge pull request #357 from hbrunn/master-_convert_field_bootstrap_4…
Browse files Browse the repository at this point in the history
…to5_sql-json

[FIX] _convert_field_bootstrap_4to5_sql: Detect json and convert its values
  • Loading branch information
pedrobaeza authored Dec 26, 2023
2 parents fdc1a1a + 2981518 commit 3c97a5a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from itertools import product

from psycopg2 import sql
from psycopg2.extras import Json

from odoo.tools.translate import _get_translation_upgrade_queries

Expand Down Expand Up @@ -393,7 +394,15 @@ def _convert_field_bootstrap_4to5_sql(cr, table, field, ids=None):
params = (tuple(ids),)
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 type(old_content) == dict:
new_content = Json(
{
key: convert_string_bootstrap_4to5(value)
for key, value in old_content.items()
}
)
else:
new_content = convert_string_bootstrap_4to5(old_content)
if old_content != new_content:
cr.execute(
sql.SQL("UPDATE {table} SET {field} = %s WHERE id = %s").format(
Expand Down

0 comments on commit 3c97a5a

Please sign in to comment.