From c03e4cb229b2357e07159734153f2bbef8954822 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 13 Nov 2019 13:58:19 +0000 Subject: [PATCH] [FIX] models: validate standard views set to noupdate in database On the registry, the set `loaded_xmlids` maintains the list of the xml ids loaded during a module upgrade. (The nodes in XML data file) According to the `noupdate` attribute on the node in the XML file, an XML ID is added to the listn either: - If noupdate is set on the node, through `_load_xmlid`: - https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/tools/convert.py#L505-L510 - https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/addons/base/models/ir_model.py#L1802 - If noupdate is not set on the node, through `_load_records` and `_update_xmlids`: - https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/tools/convert.py#L578 - https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/models.py#L4048-L4050 - https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/addons/base/models/ir_model.py#L1793 For this second case, `_update_xmlids` was called only when the condition `to_create or to_update` was met. For records not set as `noupdate="1" in the XML data file, but set to noupdate in the database (e.g. manually set by a user), the code goes trough the second path explained above (noupdate not set on the node) and the condition `to_create or to_update` was not met (See https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/models.py#L4005-L4012) and they were therefore not added in the set `loaded_xmlids` Besides, the method in charge to validate standard views `_validate_module_views`, only validates views that are in this list `loaded_xmlids`: https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/addons/base/models/ir_ui_view.py#L1194-L1210 And the method in charge to validate custom views `_validate_custom_views` only validates views with no XML ID or the module of the XML ID is not within the list of modules. Therefore, standard views set to noupdate in database were not validated at all (or indirectly, if they had a view inheriting on them that was not set to noupdate) This is not a recent regression, this is the case even in Odoo 8.0. Standard views set to `noupdate` in database but not in the XML files were not validated (or indirectly, through one of their inherited views if they had any) This revision just skips the test `to_create or to_update` so it goes through `_update_xmlids` anyway and add the xml id to the `loaded_xmlids` set, so standard views set to noupdate in database finally gets validated. Besides, `_update_xmlids` won't do anything more than add the xml id to the set, the SQL query executed in this method has a `WHERE` condition filtering out xml ids set to noupdate https://github.com/odoo/odoo/blob/eb02e9b3e00243bcf8a41b0f42273e59875ab968/odoo/addons/base/models/ir_model.py#L1784 closes odoo/odoo#40207 Signed-off-by: Denis Ledoux (dle) --- odoo/models.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 376cc5598c8..b9b2e7d8380 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4042,9 +4042,8 @@ Record ids: %(records)s data['record'] = record # create or update XMLIDs - if to_create or to_update: - imd_data_list = [data for data in data_list if data.get('xml_id')] - imd._update_xmlids(imd_data_list, update) + imd_data_list = [data for data in data_list if data.get('xml_id')] + imd._update_xmlids(imd_data_list, update) return original_self.concat(*(data['record'] for data in data_list))