tornado: Fix parsing of delete_message events with no users.

The change in 180d8abed6, while correct
for the Django part of the codebase, had the nasty side effect of
exposing a failure mode in the process_notification logic if the users
list was empty.

This, in turn, could cause our process_notification code to fail with
an IndexError when trying to process the event, which would result in
that tornado process not automatically recovering, due to the outer
try/except handler for consume triggering a NACK and thus repeating
the event.
This commit is contained in:
Tim Abbott
2020-04-09 05:39:47 -07:00
parent c4589718fc
commit a373387009

View File

@@ -1070,7 +1070,7 @@ def process_notification(notice: Mapping[str, Any]) -> None:
process_message_event(event, cast(Iterable[Mapping[str, Any]], users))
elif event['type'] == "update_message":
process_message_update_event(event, cast(Iterable[Mapping[str, Any]], users))
elif event['type'] == "delete_message" and isinstance(users[0], dict):
elif event['type'] == "delete_message" and len(users) > 0 and isinstance(users[0], dict):
# do_delete_messages used to send events with users in dict format {"id": <int>}
# This block is here for compatibility with events in that format still in the queue
# at the time of upgrade.