From fffaf735f58f1ac57781c095eb552de6d1fcdc47 Mon Sep 17 00:00:00 2001 From: xmo-odoo Date: Wed, 10 May 2017 09:39:55 +0200 Subject: [FIX] P3: list -> iterable builtins (#16811) In Python 3: * various builtins and dict methods were changed to return view/iterable objects rather than lists * and the separate Python 2 view/iterable builtins and methods were removed altogether This is problematic when using these items as list (which the happens repeatedly in Odoo), but more viciously when iterating *multiple times* over them (which also happens, which I've messed up multiple times while writing this, and which is a pain to debug even when you've just created the issue). Convert all code using these to semantics-matching cross-version helper functions to get the LCD behaviour between P2 and P3, and forbid the builtins via lint. issue #8530 --- odoo/modules/loading.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'odoo/modules/loading.py') diff --git a/odoo/modules/loading.py b/odoo/modules/loading.py index f8c65d40177..bd58376a7b9 100644 --- a/odoo/modules/loading.py +++ b/odoo/modules/loading.py @@ -20,6 +20,7 @@ import odoo.tools as tools from odoo import api, SUPERUSER_ID from odoo.modules.module import adapt_version, initialize_sys_path, load_openerp_module +from odoo.tools import pycompat _logger = logging.getLogger(__name__) _test_logger = logging.getLogger('odoo.tests') @@ -295,15 +296,15 @@ def load_modules(db, force_demo=False, status=None, update_module=False): _logger.info('updating modules list') Module.update_list() - _check_module_names(cr, itertools.chain(tools.config['init'].keys(), tools.config['update'].keys())) + _check_module_names(cr, itertools.chain(tools.config['init'], tools.config['update'])) - module_names = [k for k, v in tools.config['init'].items() if v] + module_names = [k for k, v in pycompat.items(tools.config['init']) if v] if module_names: modules = Module.search([('state', '=', 'uninstalled'), ('name', 'in', module_names)]) if modules: modules.button_install() - module_names = [k for k, v in tools.config['update'].items() if v] + module_names = [k for k, v in pycompat.items(tools.config['update']) if v] if module_names: modules = Module.search([('state', '=', 'installed'), ('name', 'in', module_names)]) if modules: @@ -391,7 +392,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): getattr(py_module, uninstall_hook)(cr, registry) Module = env['ir.module.module'] - Module.browse(modules_to_remove.values()).module_uninstall() + Module.browse(pycompat.values(modules_to_remove)).module_uninstall() # Recursive reload, should only happen once, because there should be no # modules to remove next time cr.commit() @@ -414,7 +415,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False): _logger.info('Modules loaded.') # STEP 8: call _register_hook on every model - for model in env.values(): + for model in pycompat.values(env): model._register_hook() # STEP 9: save installed/updated modules for post-install tests -- cgit v1.2.3