[blivet][master][PATCH] Do not alter the ParentList being iterated over (#1083581)

Vratislav Podzimek vpodzime at redhat.com
Tue May 27 14:29:16 UTC 2014


Removing items from a list that is being iterated over may result in various
weird, unexpected and hard to track issues (see rhbz#1083581 and rhbz#1083581).

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/devices.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index 787fbb5..cdd0642 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -296,7 +296,9 @@ class Device(util.ObjectID):
             self._parents = ParentList(appendfunc=self._addParent,
                                        removefunc=self._removeParent)
 
-        for parent in self._parents:
+        # iterate over a copy of the parent list because we are altering it in
+        # the for-cycle
+        for parent in list(self._parents):
             self._parents.remove(parent)
 
     def _setParentList(self, parents):
-- 
1.9.3



More information about the anaconda-patches mailing list