Skip to content

Commit

Permalink
[FIX] _convert_field_bootstrap_4to5_sql: consider jsonb columns
Browse files Browse the repository at this point in the history
With jsonb columns (i.e.: translations) we can't write directly the to
the blob...

TT46660
  • Loading branch information
chienandalu committed Dec 19, 2023
1 parent fdc1a1a commit 35f51c4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,27 @@ def _convert_field_bootstrap_4to5_sql(cr, table, field, ids=None):
:param list ids:
List of IDs, to restrict operation to them.
"""
cr.execute(
"SELECT udt_name FROM information_schema.columns "
"WHERE table_name = %s AND column_name = %s",
(table, field),
)
# Consider jsonb translated fields
column_type, *_ = cr.fetchone()
cr.execute("SELECT code FROM res_lang WHERE active = true")
[code for code, *_ in cr.fetchall()]
# if column_type == "jsonb":
# for lang in installed_languages:
# query = "SELECT id, {field}->>%s FROM {table}"
query = "SELECT id, {field} FROM {table}"
format_query_args = {"field": sql.Identifier(field), "table": sql.Identifier(table)}
params = ()
if ids:
query = f"{query} WHERE id IN %s"
params = (tuple(ids),)
cr.execute(sql.SQL(query).format(**format_query_args), params)
# Extract this part so we can iterate over it. Although with jsonb the update
# changes as well
for id_, old_content in cr.fetchall():
new_content = convert_string_bootstrap_4to5(old_content)
if old_content != new_content:
Expand Down

0 comments on commit 35f51c4

Please sign in to comment.