From c3077247fef29d417bc09ed95762b82906faaea5 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Thu, 23 Apr 2015 15:20:58 +0000 Subject: [PATCH] Fixes use of dict methods for Python3 In Python3 the dict.keys(), dict.values() and dict.items() methods have been changed to return iterators instead of lists. This causes issues with code that expects a list. bp python3 Change-Id: Id0d55ea4b992666848af1b1a055bc7841548cc6a --- keystone/common/cache/backends/mongo.py | 6 +++--- keystone/tests/unit/test_cache_backend_mongo.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/keystone/common/cache/backends/mongo.py b/keystone/common/cache/backends/mongo.py index 58856ac8..0598e80e 100644 --- a/keystone/common/cache/backends/mongo.py +++ b/keystone/common/cache/backends/mongo.py @@ -451,7 +451,7 @@ class MongoApi(object): doc_date = self._get_doc_date() insert_refs = [] update_refs = [] - existing_docs = self._get_results_as_dict(mapping.keys()) + existing_docs = self._get_results_as_dict(list(mapping.keys())) for key, value in mapping.items(): ref = self._get_cache_entry(key, value.payload, value.metadata, doc_date) @@ -536,7 +536,7 @@ class BaseTransform(AbstractManipulator): def transform_incoming(self, son, collection): """Used while saving data to MongoDB.""" - for (key, value) in son.items(): + for (key, value) in list(son.items()): if isinstance(value, api.CachedValue): son[key] = value.payload # key is 'value' field here son['meta'] = value.metadata @@ -553,7 +553,7 @@ class BaseTransform(AbstractManipulator): ('_id', 'value', 'meta', 'doc_date')): payload = son.pop('value', None) metadata = son.pop('meta', None) - for (key, value) in son.items(): + for (key, value) in list(son.items()): if isinstance(value, dict): son[key] = self.transform_outgoing(value, collection) if metadata is not None: diff --git a/keystone/tests/unit/test_cache_backend_mongo.py b/keystone/tests/unit/test_cache_backend_mongo.py index a56bf754..8afd5e8e 100644 --- a/keystone/tests/unit/test_cache_backend_mongo.py +++ b/keystone/tests/unit/test_cache_backend_mongo.py @@ -160,7 +160,7 @@ class MockCollection(object): return new if isinstance(obj, dict): new = container() - for key, value in obj.items(): + for key, value in list(obj.items()): new[key] = self._copy_doc(value, container) return new else: