Fix dictionary change during iteration

During dumping the result_dict it we iterate over a copy of it and
filter out some variables. This results in the error below [1]. The
reason is the result_dict.keys() doesn't return a new set of the
existing keys but a view of them which is changed then during
iteration. This can be fixed by creating a list of the keys and
iterating over that.

[1] Log:

 [WARNING]: Failure using method (v2_runner_on_ok) in callback plugin
  (<ansible.plugins.callback.zuul_stream.CallbackModule object at
  0x7f5d41b73b70>): dictionary changed size during iteration

Change-Id: I2ad148002dbe471296b4c1b0e448f2cc03ce2913
This commit is contained in:
Tobias Henkel 2017-07-13 09:00:15 +02:00
parent 5b7a042e3b
commit 27d51685c9
1 changed files with 1 additions and 1 deletions

View File

@ -447,7 +447,7 @@ class CallbackModule(default.CallbackModule):
def _dump_result_dict(self, result_dict):
result_dict = result_dict.copy()
for key in result_dict.keys():
for key in list(result_dict.keys()):
if key.startswith('_ansible') or key == 'zuul_log_id':
del result_dict[key]
return result_dict