GH-56902 Copy to new list from dict.items() return

dict.items() in pytho2 returns a list of tuples which can be iterated
while modifying the dict. In python 3 it returns a view which is tied to
the underlying dict, meaning the modifications to the dict while
iterating are unsafe.

This commit generates new list containing the tuples from the iterator
in python 3 which breaks the link to the dict, allowing the dict to be
modified while iterating the list.

In python 2 it would simply copy the list.

Fixes #56902
pull/57028/head
Robert Bridge 6 years ago committed by Gonéri Le Bouder
parent a946d5d8ce
commit 0d75e2659e

@ -938,7 +938,7 @@ def get_diff_final_resource(client, module, security_group):
'vpc_id': rule_sg.get('vpc_id', module.params['vpc_id']),
'vpc_peering_connection_id': rule_sg.get('vpc_peering_connection_id')
}]
for k, v in format_rule['user_id_group_pairs'][0].items():
for k, v in list(format_rule['user_id_group_pairs'][0].items()):
if v is None:
format_rule['user_id_group_pairs'][0].pop(k)
final_rules.append(format_rule)

Loading…
Cancel
Save