From 7d3cc250ef548771f788b9f0119eca1d8164ff96 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Thu, 5 Dec 2019 03:02:59 -0700 Subject: [PATCH] Fix ec2 filter dict iteration for python3.8 (#65521) Python now throws a RuntimeError if dict keys are modified mid-iteration. https://bugs.python.org/issue36452 Cast filter dicts to list before iteration. Fixes: 65024 Related: 65434 --- lib/ansible/modules/cloud/amazon/ec2_instance.py | 2 +- lib/ansible/modules/cloud/amazon/ec2_vol_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_instance.py b/lib/ansible/modules/cloud/amazon/ec2_instance.py index d274efd9163..b46a69e71a3 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_instance.py +++ b/lib/ansible/modules/cloud/amazon/ec2_instance.py @@ -1393,7 +1393,7 @@ def find_instances(ec2, ids=None, filters=None): elif filters is None: module.fail_json(msg="No filters provided when they were required") elif filters is not None: - for key in filters.keys(): + for key in list(filters.keys()): if not key.startswith("tag:"): filters[key.replace("_", "-")] = filters.pop(key) return list(paginator.paginate( diff --git a/lib/ansible/modules/cloud/amazon/ec2_vol_info.py b/lib/ansible/modules/cloud/amazon/ec2_vol_info.py index fecaab0904c..91c989e6bfc 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vol_info.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vol_info.py @@ -108,7 +108,7 @@ def list_ec2_volumes(connection, module, region): # Replace filter key underscores with dashes, for compatibility, except if we're dealing with tags sanitized_filters = module.params.get("filters") - for key in sanitized_filters: + for key in list(sanitized_filters): if not key.startswith("tag:"): sanitized_filters[key.replace("_", "-")] = sanitized_filters.pop(key) volume_dict_array = []