[FIX] web_editor: remove lang from ctx by poping it, not setting None

Since commit [1], the lang was removed from the context by setting it to
None.
In Odoo 16 and since jsonb, it's not correct, the lang should simply be
popped from the context.
Indeed, having `lang=None` in the context will not return any value when
reading the arch if the arch has no `en_US` default value.

The previous commit will make it so the translations will be forwarded
to custom snippets when saving a snippet. With that commit, the issue
described above will be problematic and lead to a crash.

There is probably other legit ways to reproduce the issue which are not
yet found as we don't really use non english DB often.

Step to reproduce (following previous commit):
- Create a db with french only and install website.
- Then enable dutch and add it on the website as second lang
- Drop a title snippet & translate it in the dutch version
- Save and go back to the main lang (fr)
- Drag & drop again this newly saved snippet (custom snippet)
- Save and to to dutch version
- Enter translate mode
-> A traceback will be shown, because `get_related_views` will fail on
   "empty etree document", because when in the stack doing
   `etree.fromstring(view.arch)`, it will fail since arch = ''.

Step to reproduce (without the previous commit):
- Remove the `en_US` jsonb key from a view, eg
  `update ir_ui_view set arch_db = (select arch_db - 'en_US' from ir_ui_view where id = 4) where id = 4;`
- Start odoo-bin in `shell` mode
- Do `self.env['ir.ui.view'].browse(4).arch` -> Will output the arch
- Do `self.env['ir.ui.view'].browse(4).with_context(lang=None).arch`
-> This will crash on record not found error.

[1]: https://github.com/odoo/odoo/commit/fdb9f8273be62d0a6d8051f7ca0a66cdf22ae5e7

task-3375518

X-original-commit: 9cb17bc9cb1490219d1488c99e419a84681ca121
Part-of: odoo/odoo#150945
This commit is contained in:
Romain Derie
2024-01-25 18:13:03 +00:00
parent 8255fd6bff
commit 4fedd2a490
+6 -1
View File
@@ -349,7 +349,12 @@ class IrUiView(models.Model):
``bundles=True`` returns also the asset bundles
"""
user_groups = set(self.env.user.groups_id)
View = self.with_context(active_test=False, lang=None)
new_context = {
**self._context,
'active_test': False,
}
new_context.pop('lang', None)
View = self.with_context(new_context)
views = View._views_get(key, bundles=bundles)
return views.filtered(lambda v: not v.groups_id or len(user_groups.intersection(v.groups_id)))