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

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

Conversation

chienandalu
Copy link
Member

ref: OCA/OpenUpgrade#4263

Options for the fix:

  • This WIP: consider tranlated fields in _convert_field_bootstrap_4to5_sql
  • Use the orm method in the issued OpenUpgrade script

cc @Tecnativa TT46660

With jsonb columns (i.e.: translations) we can't write directly the to
the blob...

TT46660
@dansanti
Copy link

hello, here I do:
1.- make import:

from psycopg2 import sql

from psycopg2 import sql, extras

2.- delete from

[code for code, *_ in cr.fetchall()]

to
# query = "SELECT id, {field}->>%s FROM {table}"

3.- then adding to your code:

for id_, old_content in cr.fetchall():

`

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
Copy link
Member

hbrunn commented Dec 23, 2023

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

@pedrobaeza
Copy link
Member

Closed in favor of #357

@pedrobaeza pedrobaeza closed this Dec 26, 2023
@pedrobaeza pedrobaeza deleted the fix-_convert_field_bootstrap_4to5_sql-jsonb branch December 26, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants