From d5ed47a11fa411c20353bc47492dca2177d4d9d1 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 19 Jul 2023 12:54:02 +0000 Subject: [PATCH] [IMP] base: simplify _xmlid_lookup cache The _xmlid_lookup cache contains the id of the ir.model.data with is unused, making cache pupulation and usage more complex than needed. Removing this id in prevision of the next commit Part-of: odoo/odoo#129029 --- addons/product_margin/wizard/product_margin.py | 2 +- addons/purchase/models/purchase.py | 8 ++++---- addons/website_forum/controllers/website_forum.py | 2 +- odoo/addons/base/models/ir_model.py | 9 +++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/product_margin/wizard/product_margin.py b/addons/product_margin/wizard/product_margin.py index 9453a9aeb4d..0b2e6153912 100644 --- a/addons/product_margin/wizard/product_margin.py +++ b/addons/product_margin/wizard/product_margin.py @@ -24,7 +24,7 @@ class ProductMargin(models.TransientModel): def ref(xml_id): proxy = self.env['ir.model.data'] - return proxy._xmlid_lookup(xml_id)[2] + return proxy._xmlid_lookup(xml_id)[1] search_view_id = ref('product.product_search_form_view') graph_view_id = ref('product_margin.view_product_margin_graph') diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index ef290a254ef..7a2cfc4d47e 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -430,13 +430,13 @@ class PurchaseOrder(models.Model): ir_model_data = self.env['ir.model.data'] try: if self.env.context.get('send_rfq', False): - template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase')[2] + template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase')[1] else: - template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase_done')[2] + template_id = ir_model_data._xmlid_lookup('purchase.email_template_edi_purchase_done')[1] except ValueError: template_id = False try: - compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[2] + compose_form_id = ir_model_data._xmlid_lookup('mail.email_compose_message_wizard_form')[1] except ValueError: compose_form_id = False ctx = dict(self.env.context or {}) @@ -792,7 +792,7 @@ class PurchaseOrder(models.Model): def _send_reminder_open_composer(self,template_id): self.ensure_one() try: - compose_form_id = self.env['ir.model.data']._xmlid_lookup('mail.email_compose_message_wizard_form')[2] + compose_form_id = self.env['ir.model.data']._xmlid_lookup('mail.email_compose_message_wizard_form')[1] except ValueError: compose_form_id = False ctx = dict(self.env.context or {}) diff --git a/addons/website_forum/controllers/website_forum.py b/addons/website_forum/controllers/website_forum.py index 7466710c848..4b7dcfc3172 100644 --- a/addons/website_forum/controllers/website_forum.py +++ b/addons/website_forum/controllers/website_forum.py @@ -678,7 +678,7 @@ class WebsiteForum(WebsiteProfile): vote_ids = Vote.search([('user_id', '=', user.id)]) # activity by user. - comment = Data._xmlid_lookup('mail.mt_comment')[2] + comment = Data._xmlid_lookup('mail.mt_comment')[1] activities = Activity.search( [('res_id', 'in', (user_question_ids + user_answer_ids).ids), ('model', '=', 'forum.post'), ('subtype_id', '!=', comment)], diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index 1f531a3b4c4..24160a2eff6 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -2014,10 +2014,10 @@ class IrModelData(models.Model): Return (id, res_model, res_id) or raise ValueError if not found """ module, name = xmlid.split('.', 1) - query = "SELECT id, model, res_id FROM ir_model_data WHERE module=%s AND name=%s" + query = "SELECT model, res_id FROM ir_model_data WHERE module=%s AND name=%s" self.env.cr.execute(query, [module, name]) result = self.env.cr.fetchone() - if not (result and result[2]): + if not (result and result[1]): raise ValueError('External ID not found in the system: %s' % xmlid) return result @@ -2025,7 +2025,7 @@ class IrModelData(models.Model): def _xmlid_to_res_model_res_id(self, xmlid, raise_if_not_found=False): """ Return (res_model, res_id)""" try: - return self._xmlid_lookup(xmlid)[1:3] + return self._xmlid_lookup(xmlid) except ValueError: if raise_if_not_found: raise @@ -2040,7 +2040,7 @@ class IrModelData(models.Model): def check_object_reference(self, module, xml_id, raise_on_access_error=False): """Returns (model, res_id) corresponding to a given module and xml_id (cached), if and only if the user has the necessary access rights to see that object, otherwise raise a ValueError if raise_on_access_error is True or returns a tuple (model found, False)""" - model, res_id = self._xmlid_lookup("%s.%s" % (module, xml_id))[1:3] + model, res_id = self._xmlid_lookup("%s.%s" % (module, xml_id)) #search on id found in result to check if current user has read access right if self.env[model].search([('id', '=', res_id)]): return model, res_id @@ -2114,6 +2114,7 @@ class IrModelData(models.Model): try: self.env.cr.execute(query, [arg for row in sub_rows for arg in row]) self.env.registry.clear_cache() + except Exception: _logger.error("Failed to insert ir_model_data\n%s", "\n".join(str(row) for row in sub_rows)) raise