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

[FIX] models: do not erase master version #31330

Closed
wants to merge 1 commit into
base: 12.0
from

Conversation

Projects
None yet
3 participants
@mart-e
Copy link
Contributor

mart-e commented Feb 21, 2019

For a translated field with a callable method (e.g. xml_translate), when
modifying the value of this field in another language than en_US, the master
version was lost.

Before this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Titre</h1>"
>>> record.arch
"<h1>Titre</h1>"  # lost English version

After this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Title</h1>"  # write had no effect
>>> record.arch
"<h1>Title</h1>"

When modifying a translated HTML field in English, a matching to detect the
difference and avoid losing the translations is done.
This is not supported for update in another language.
The main reason is the difficulty to detect changes in the architecture.

To update translations, the supported way is to go to the list of translations
and update them there.

Before this patch, the given value in another language was given to the SQL
query and made an update in database:
if single_lang or not (has_translation and field.translate is True)
-> True or not (True and False) -> True

If a field is callable, it should also be ignored, the same way than
translate=True fields

opw-1887162

[FIX] models: do not erase master version
For a translated field with a callable method (e.g. xml_translate), when
modifying the value of this field in another language than en_US, the master
version was lost.

Before this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Titre</h1>"
>>> record.arch
"<h1>Titre</h1>"  # lost English version

After this patch:

>>> record.arch = "<h1>Title</h1>"
>>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>"
>>> record.with_context(lang='fr_FR').arch
"<h1>Title</h1>"  # write had no effect
>>> record.arch
"<h1>Title</h1>"

When modifying a translated HTML field in English, a matching to detect the
difference and avoid losing the translations is done.
This is not supported for update in another language.
The main reason is the difficulty to detect changes in the architecture.

To update translations, the supported way is to go to the list of translations
and update them there.

Before this patch, the given value in another language was given to the SQL
query and made an update in database:
if single_lang or not (has_translation and field.translate is True)
-> True or not (True and False) -> True

If a field is callable, it should also be ignored, the same way than
translate=True fields

opw-1887162

@robodoo robodoo added the seen 🙂 label Feb 21, 2019

@mart-e mart-e added the OE label Feb 21, 2019

@robodoo robodoo added the CI 🤖 label Feb 21, 2019

@mart-e

This comment has been minimized.

Copy link
Contributor Author

mart-e commented Feb 26, 2019

robodoo r+

@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Feb 26, 2019

Merged, thanks!

@mart-e mart-e deleted the odoo-dev:12.0-no-write-html-translation-mat branch Feb 26, 2019

@@ -3360,7 +3360,7 @@ def _write(self, vals):
_logger.warning('Field %s is deprecated: %s', field, field.deprecated)

if field.column_type:
if single_lang or not (has_translation and field.translate is True):

This comment has been minimized.

@odony

odony Mar 4, 2019

Contributor

This may silently break cases where the business logic relied on the previous "unspecified" behavior. Apparently it was the case in web_studio, so creation/update of new inherited views does not work anymore in non-english languages there.
We could consider that web_studio should force lang=None or use arch_base instead of arch, but this can similarly affect other "legit" cases. Shouldn't we at least log a warning when the unspecified case occurs (i.e. write to an XML translatable field in a non-master lang), and see if we detect anything in the tests?

This comment has been minimized.

@odony

odony Mar 4, 2019

Contributor

This may need to be patched in 11.0, if you backported this patch already. /cc @kebeclibre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.