OCA / openupgradelib

A library with support functions to be called from Odoo migration scripts.
GNU Affero General Public License v3.0
85 stars 171 forks source link

[WIP][FIX] _convert_field_bootstrap_4to5_sql: consider jsonb columns #356

Closed chienandalu closed 8 months ago

chienandalu commented 8 months ago

ref: https://github.com/OCA/OpenUpgrade/issues/4263

Options for the fix:

cc @Tecnativa TT46660

dansanti commented 8 months ago

hello, here I do: 1.- make import: https://github.com/OCA/openupgradelib/blob/35f51c4301a691d78e9e84cdc3651ff385ccdb92/openupgradelib/openupgrade_160.py#L11 from psycopg2 import sql, extras

2.- delete from https://github.com/OCA/openupgradelib/blob/35f51c4301a691d78e9e84cdc3651ff385ccdb92/openupgradelib/openupgrade_160.py#L396 to https://github.com/OCA/openupgradelib/blob/35f51c4301a691d78e9e84cdc3651ff385ccdb92/openupgradelib/openupgrade_160.py#L399

3.- then adding to your code: https://github.com/OCA/openupgradelib/blob/35f51c4301a691d78e9e84cdc3651ff385ccdb92/openupgradelib/openupgrade_160.py#L409

`

for id_, old_content in cr.fetchall():
    new_content = {}
    if column_type == "jsonb":
        for lang, lang_old_content in old_content.items():
            lang_new_content = convert_string_bootstrap_4to5(lang_old_content)
            new_content[lang] = lang_new_content
        new_content = extras.Json(new_content)
        old_content = extras.Json(old_content)
    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(
                **format_query_args
            ),
            (
                new_content,
                id_,
            ),
        )

`

hbrunn commented 8 months ago

@chienandalu I ran into the same problem and propose to just have psycopg2 sort it out: #357

pedrobaeza commented 8 months ago

Closed in favor of #357