From 05cb4ba4e97d8cbffaf1c16451c488db4a90a878 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Apr 28 2016 14:22:07 +0000 Subject: sysrestore: Iterate over a list of dict keys In Python 3, dict.keys() returns a key view. It is not safe to delete dict keys when iterating over this view. Convert the keys to list first. Part of the work for https://fedorahosted.org/freeipa/ticket/4985 Reviewed-By: Martin Basti --- diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py index c1c2bce..e0d0908 100644 --- a/ipapython/sysrestore.py +++ b/ipapython/sysrestore.py @@ -347,7 +347,7 @@ class StateFile: """ root_logger.debug("Saving StateFile to '%s'", self._path) - for module in self.modules.keys(): + for module in list(self.modules.keys()): if len(self.modules[module]) == 0: del self.modules[module]