Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] base: keep translations for null src while upgrade
The method ``update_translatable_fields`` is inspired in the core ``_get_translation_upgrade_queries`` method, which had a bug that has been recently addressed in odoo/odoo#168038 Also, we're avoiding removing any original ir_translation record so we can address any further issue easly without needing to redump the table from the former DB. For html/xml tranlatable fields we'll use ``openupgrade_160.migrate_translations_to_jsonb`` which calls to the proper core method in ``end-migration``. Ideally we'd like to do everything with that method, but it relies on having the models already in the registry, and that doesn't happen when we're in `base`. Rationale from Odoo's fix: Before Odoo 16.0, it is possible to have database column whose value is ``NULL`` but still has translations in the ir_translation table. And these translations can be displayed correctly in the UI. How to reproduce before Odoo 16.0: 1. Open the form view of a record with non-required translated field. E.g. product.template.sale_description 2. Create a new record without touching the translated field for test 3. Directly click the translation button and fill all translations 4. click save The column for the record's translated field has ``NULL`` value, and the ir_translation table has new translation records with ``NULL`` in the src column During upgrade, when the column value is converted to jsonb for the translated field by the ORM, it will still be ``NULL``. And in the upgrade script when update the value with all translations, the result will still be ``NULL``. E.g. ``NULL || '{"fr_FR": "french"}'::jsonb`` ``NULL || '{"en_US": "english", "fr_FR": "french"}'::jsonb`` In this commit, for the above corner case, we assume the src was empty string instead of NULL. In the above example, the result would be ``'{"en_US": ""}'::jsonb || '{"fr_FR": "french"}'::jsonb`` ``'{"en_US": ""}'::jsonb || '{"en_US": "english", "fr_FR": "french"}'::jsonb`` TT49615
- Loading branch information