mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-11 03:31:29 -07:00
dictionary changed size during iteration error (#37454)
Iterating an object and changing it at the same time is unsecure and no longer permitted in Python >= 3.6 Provisioning an instance fail with the Python error: "RuntimeError: dictionary changed size during iteration"
This commit is contained in:
parent
72657ce815
commit
7a5e7c83d3
1 changed files with 5 additions and 1 deletions
|
@ -205,6 +205,7 @@ anti_affinity_with:
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.cloudscale import AnsibleCloudscaleBase, cloudscale_argument_spec
|
from ansible.module_utils.cloudscale import AnsibleCloudscaleBase, cloudscale_argument_spec
|
||||||
|
@ -296,8 +297,11 @@ class AnsibleCloudscaleServer(AnsibleCloudscaleBase):
|
||||||
self._module.fail_json(msg='Missing required parameter(s) to create a new server: %s.' %
|
self._module.fail_json(msg='Missing required parameter(s) to create a new server: %s.' %
|
||||||
' '.join(missing_parameters))
|
' '.join(missing_parameters))
|
||||||
|
|
||||||
|
# Deepcopy: Duplicate the data object for iteration, because
|
||||||
|
# iterating an object and changing it at the same time is insecure
|
||||||
|
|
||||||
# Sanitize data dictionary
|
# Sanitize data dictionary
|
||||||
for k, v in data.items():
|
for k, v in deepcopy(data).items():
|
||||||
|
|
||||||
# Remove items not relevant to the create server call
|
# Remove items not relevant to the create server call
|
||||||
if k in ('api_token', 'api_timeout', 'uuid', 'state'):
|
if k in ('api_token', 'api_timeout', 'uuid', 'state'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue