summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-04-19 19:46:58 +0000
committerGerrit Code Review <review@openstack.org>2018-04-19 19:46:58 +0000
commitf51e726f643b65ee816dff66cc9a3c932c0bca23 (patch)
tree2abfa7802d23c1df19c78cfbe1760a5b293e7f82
parent0c9a4fd659af8d8eb19fb39af52a2106b2c307a5 (diff)
parentcfadd2bbe45b2de8d060a0ed003ba96e26235722 (diff)
downloadtrove-f51e726f643b65ee816dff66cc9a3c932c0bca23.tar.gz
Merge "Fix dict iteration in PropertiesCodec"
-rw-r--r--trove/common/stream_codecs.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/trove/common/stream_codecs.py b/trove/common/stream_codecs.py
index 752dbb9a..a85d6c68 100644
--- a/trove/common/stream_codecs.py
+++ b/trove/common/stream_codecs.py
@@ -342,7 +342,14 @@ class PropertiesCodec(StreamCodec):
if self._unpack_singletons:
# Unpack singleton values.
- for k, v in data_dict.items():
+ # NOTE(zhaochao): In Python 3.x, dict.items() returns a view
+ # object, which will reflect the changes of the dict itself:
+ # https://docs.python.org/3/library/stdtypes.html#dict-views
+ # This means as we're changing the dict, dict.items() cannot
+ # guarantee we're safely iterating all entries in the dict.
+ # Manually converting the result of dict.items() to a list will
+ # fix.
+ for k, v in list(data_dict.items()):
data_dict.update({k: trove_utils.unpack_singleton(v)})
return data_dict