diff options
| author | xmo-odoo <xmo@odoo.com> | 2017-05-10 09:39:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-10 09:39:55 +0200 |
| commit | fffaf735f58f1ac57781c095eb552de6d1fcdc47 (patch) | |
| tree | 88ab0ab65430d871862a836524e0ecc890d1674d /odoo/modules/registry.py | |
| parent | 10eee18a047d35305dc46282e610e88936d81ffc (diff) | |
[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
Diffstat (limited to 'odoo/modules/registry.py')
| -rw-r--r-- | odoo/modules/registry.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index e0cfb532fd1..71d7b5d9fbe 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -16,7 +16,8 @@ import threading import odoo from .. import SUPERUSER_ID from odoo.tools import (assertion_report, lazy_classproperty, config, - lazy_property, table_exists, topological_sort, OrderedSet) + lazy_property, table_exists, topological_sort, + OrderedSet, pycompat) from odoo.tools.lru import LRU _logger = logging.getLogger(__name__) @@ -156,7 +157,7 @@ class Registry(Mapping): def delete_all(cls): """ Delete all the registries. """ with cls._lock: - for db_name in cls.registries.keys(): + for db_name in list(pycompat.keys(cls.registries)): cls.delete(db_name) # @@ -192,8 +193,8 @@ class Registry(Mapping): # map fields on their dependents dependents = { field: set(dep for dep, _ in model._field_triggers[field] if dep != field) - for model in self.itervalues() - for field in model._fields.itervalues() + for model in pycompat.values(self) + for field in pycompat.values(model._fields) } # sort them topologically, and associate a sequence number to each field mapping = { @@ -261,7 +262,7 @@ class Registry(Mapping): env['ir.model']._add_manual_models() # prepare the setup on all models - models = env.values() + models = list(pycompat.values(env)) for model in models: model._prepare_setup() @@ -310,18 +311,18 @@ class Registry(Mapping): # make sure all tables are present missing = [name - for name, model in env.items() + for name, model in pycompat.items(env) if not model._abstract and not table_exists(cr, model._table)] if missing: _logger.warning("Models have no table: %s.", ", ".join(missing)) # recreate missing tables following model dependencies - deps = {name: model._depends for name, model in env.items()} + deps = {name: model._depends for name, model in pycompat.items(env)} for name in topological_sort(deps): if name in missing: _logger.info("Recreate table of model %s.", name) env[name].init() # check again, and log errors if tables are still missing - for name, model in env.items(): + for name, model in pycompat.items(env): if not model._abstract and not table_exists(cr, model._table): _logger.error("Model %s has no table.", name) @@ -340,7 +341,7 @@ class Registry(Mapping): """ Clear the caches associated to methods decorated with ``tools.ormcache`` or ``tools.ormcache_multi`` for all the models. """ - for model in self.models.itervalues(): + for model in pycompat.values(self.models): model.clear_caches() def setup_signaling(self): |
