Juan Hernandez has uploaded a new change for review.

Change subject: sdk: Avoid altering dictionary while removing elements
......................................................................

sdk: Avoid altering dictionary while removing elements

Currently the "clear" method of the "Cache" class iterates the keys of
the dictionary and removes them, but this causes errors in Python 3.
This patch changes that methods so that it makes a copy of the list of
keys and iterates it intead of the original one.

Change-Id: Iff458d9e432c47e4c5d9ef7ec3e1178d718be497
Related: https://bugzilla.redhat.com/1096137
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/ovirtsdk/infrastructure/cache.py
1 file changed, 5 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/52/41352/1

diff --git a/src/ovirtsdk/infrastructure/cache.py 
b/src/ovirtsdk/infrastructure/cache.py
index 7533ba4..0406388 100644
--- a/src/ovirtsdk/infrastructure/cache.py
+++ b/src/ovirtsdk/infrastructure/cache.py
@@ -121,7 +121,11 @@
         [@param force: force remove regardless cache mode]
         '''
         with self.__lock:
-            for item in self.__cache.keys():
+            # We need to make a copy of the list of keys, as it will be
+            # modified as we iterate and that causes exceptions in
+            # Python 3:
+            keys = list(self.__cache.keys())
+            for item in keys:
                 self.remove(key=item, force=force)
 
     def remove(self, key, force=False):


-- 
To view, visit https://gerrit.ovirt.org/41352
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff458d9e432c47e4c5d9ef7ec3e1178d718be497
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to