From 50541486332fa8e56ba4a890746bc8ecb60d7996 Mon Sep 17 00:00:00 2001 From: nda Date: Thu, 28 Dec 2023 17:20:33 -0400 Subject: [PATCH] [FIX] base_import_module: avoid warning when browsing industry modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An ormcache has been added to a method that takes lists as parameters but lists are not hashable. steps to reproduce: - go to apps and click on on 'Industries' before this commit: - a warning is raised in the logs: WARNING industry odoo.tools.cache: cache lookup error on ('ir.module.module', , ['icon', 'icon_flag', 'to_buy', 'name', 'state', 'summary', 'website', 'application', 'module_type', 'shortdesc'], 'industries', False, ['&', '!', ['name', '=like', 'theme_%'], '&', ['application', '=', True], ['module_type', '=', 'industries']], 80, 0) Traceback (most recent call last): File "/home/nda/dev/odoo/17.0/odoo/odoo/tools/cache.py", line 99, in lookup r = d[key] File "", line 2, in __getitem__ File "/home/nda/dev/odoo/17.0/odoo/odoo/tools/func.py", line 87, in locked return func(inst, *args, **kwargs) File "/home/nda/dev/odoo/17.0/odoo/odoo/tools/lru.py", line 34, in __getitem__ a = self.d[obj] TypeError: unhashable type: 'list' after this commit: - ormcache is properly used opw-3660052 closes odoo/odoo#147730 Signed-off-by: Rémy Voet (ryv) --- addons/base_import_module/models/ir_module.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/base_import_module/models/ir_module.py b/addons/base_import_module/models/ir_module.py index 2a18636b015..fabd42a8b48 100644 --- a/addons/base_import_module/models/ir_module.py +++ b/addons/base_import_module/models/ir_module.py @@ -25,6 +25,8 @@ _logger = logging.getLogger(__name__) APPS_URL = "https://apps.odoo.com" MAX_FILE_SIZE = 100 * 1024 * 1024 # in megabytes +def to_tuple(t): + return tuple(map(to_tuple, t)) if isinstance(t, (list, tuple)) else t class IrModule(models.Model): _inherit = "ir.module.module" @@ -283,8 +285,9 @@ class IrModule(models.Model): @api.model def web_search_read(self, domain, specification, offset=0, limit=None, order=None, count_limit=None): if _domain_asks_for_industries(domain): - fields_name = list(specification.keys()) - modules_list = self._get_modules_from_apps(fields_name, 'industries', False, domain, offset=offset, limit=limit) + fields_name = tuple(specification.keys()) + domain_tuple = to_tuple(domain or []) + modules_list = self._get_modules_from_apps(fields_name, 'industries', False, domain_tuple, offset=offset, limit=limit) return { 'length': len(modules_list), 'records': modules_list, @@ -303,7 +306,7 @@ class IrModule(models.Model): } def web_read(self, specification): - fields = list(specification.keys()) + fields = tuple(specification.keys()) module_type = self.env.context.get('module_type', 'official') if module_type != 'official': modules_list = self._get_modules_from_apps(fields, module_type, self.env.context.get('module_name'))