From 62e04f82e38ea60fbe783e5707dd7ea14ba9ff28 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 30 Sep 2025 11:16:31 +0200 Subject: [PATCH] [FIX] util.convert_field_to_translatable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the function idempotent. It was silently break the translations. ``` ❯ psql -d test-19 -c 'select name from res_country where id=1;' ┌──────────────────────┐ │ name │ ├──────────────────────┤ │ {"en_US": "Andorra"} │ └──────────────────────┘ (1 row) Time: 1.353 ms ❯ ./odoo-bin shell --upgrade-path ../../upgrade-util/src -d test-19 --log-handler=:CRITICAL env: odoo: )> openerp: )> self: res.users(1,) In [1]: from odoo.upgrade import util In [2]: util.convert_field_to_translatable(env.cr, "res.country", "name") In [3]: env.cr.commit() In [4]: Do you really want to exit ([y]/n)? ^D ❯ psql -d test-19 -c 'select name from res_country where id=1;' ┌─────────────────────────────────┐ │ name │ ├─────────────────────────────────┤ │ {"en_US": {"en_US": "Andorra"}} │ └─────────────────────────────────┘ (1 row) Time: 1.360 ms ❯ ``` --- src/util/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/fields.py b/src/util/fields.py index dcd03dbca..2194cfea5 100644 --- a/src/util/fields.py +++ b/src/util/fields.py @@ -1081,7 +1081,7 @@ def _extract_data_as_attachment(cr, model, field, encoded=True, name_field=None, def convert_field_to_translatable(cr, model, field): table = table_of_model(cr, model) ctype = column_type(cr, table, field) - if not ctype or ctype == "json": + if not ctype or ctype == "jsonb": return alter_column_type(cr, table, field, "jsonb", "jsonb_build_object('en_US', {0})")