Skip to content

Commit

Permalink
Iterate over a copy of keys when moving fields in the logging event
Browse files Browse the repository at this point in the history
This prevents a "dictionary changed size during iteration" exception
because before we iterated over the dictionary while modifying its
contents which is never a good idea.

Closes #2.
  • Loading branch information
eht16 committed Nov 26, 2016
1 parent 321a99a commit a321180
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions logstash_async/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ def _move_extra_record_fields_to_prefix(self, message):
return # early out if no prefix is configured

field_skip_list = LOGSTASH_MESSAGE_FIELD_LIST + [self._extra_prefix]
for key, value in message.items():
for key in list(message):
if key not in field_skip_list:
message[self._extra_prefix][key] = value
del message[key]
message[self._extra_prefix][key] = message.pop(key)

# ----------------------------------------------------------------------
def _serialize(self, message):
Expand Down

0 comments on commit a321180

Please sign in to comment.