From 648a894b515d2e9d83e94dd3095b3ddf62d7e77d Mon Sep 17 00:00:00 2001 From: Idan Hefetz Date: Wed, 17 Jan 2018 10:42:26 +0000 Subject: [PATCH] bugfix - dict item removed during iteration Change-Id: I283f6ca968a6289db6d218d37fb6e5b197130d46 --- vitrage/graph/algo_driver/networkx_algorithm.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vitrage/graph/algo_driver/networkx_algorithm.py b/vitrage/graph/algo_driver/networkx_algorithm.py index 8e3ddcd9d..631695ab5 100644 --- a/vitrage/graph/algo_driver/networkx_algorithm.py +++ b/vitrage/graph/algo_driver/networkx_algorithm.py @@ -230,6 +230,8 @@ class NXAlgorithm(GraphAlgorithm): @staticmethod def _apply_edge_attr_filter(graph, edge_attr_filter): - for source, target, edge_data in graph._g.edges_iter(data=True): - if not check_filter(edge_data, edge_attr_filter): - graph._g.remove_edge(u=source, v=target) + edges_iter = graph._g.edges_iter(data=True, keys=True) + edges_to_remove = [(u, v, k) for (u, v, k, d) in edges_iter + if not check_filter(d, edge_attr_filter)] + for source, target, key in edges_to_remove: + graph._g.remove_edge(u=source, v=target, key=key)