From 0d75e2659e39ce4c751c592409f46e6215a22711 Mon Sep 17 00:00:00 2001 From: Robert Bridge Date: Fri, 24 May 2019 11:29:17 +0100 Subject: [PATCH] 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 --- lib/ansible/modules/cloud/amazon/ec2_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_group.py b/lib/ansible/modules/cloud/amazon/ec2_group.py index 8c502bffec7..7f85fced412 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_group.py +++ b/lib/ansible/modules/cloud/amazon/ec2_group.py @@ -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)