Repository: zulip/zulip-terminal

Issue:
KeyError: 'flags'
![Screen Shot 2021-02-12 at 8 38 22 PM](https://user-images.githubusercontent.com/57010984/107838385-ac0afd00-6d73-11eb-935f-14d38cce2ee2.png)

The following error was in my zulip-terminal-thread-exceptions.log:

Traceback (most recent call last):
  File "/Users/kellyfoulk/Documents/code/zulip-terminal/zulipterminal/model.py", line 1265, in poll_for_events
    self.event_actions[event['type']](event)
  File "/Users/kellyfoulk/Documents/code/zulip-terminal/zulipterminal/model.py", line 1124, in _handle_update_message_flags_event
    if flag_to_change not in msg['flags']:
KeyError: 'flags'

I was not doing anything in the terminal when this appeared. I had been on my browser and when I moved back to the terminal this was showing on the screen. This was about 1.5 hours after I had issue #919 occur and it was within the same zulip-terminal instance.

Running Zulip Terminal 0.6.0+git on mac in a Z shell

Discussion:

Patch:
diff --git a/zulipterminal/model.py b/zulipterminal/model.py
index a53d2a6..f098e66 100644
--- a/zulipterminal/model.py
+++ b/zulipterminal/model.py
@@ -1427,7 +1427,7 @@ class Model:
         assert event["type"] == "reaction"
         message_id = event["message_id"]
         # If the message is indexed
-        if self.index["messages"][message_id] != {}:
+        if message_id in self.index["messages"]:
 
             message = self.index["messages"][message_id]
             if event["op"] == "add":


Test patch:
diff --git a/tests/model/test_model.py b/tests/model/test_model.py
index 7aab54f..d82ef87 100644
--- a/tests/model/test_model.py
+++ b/tests/model/test_model.py
@@ -2041,9 +2041,7 @@ class TestModel:
         def _factory(msgs: MsgsType):
             return {
                 "messages": {
-                    message_id: {}
-                    if reactions is None
-                    else {
+                    message_id: {
                         "id": message_id,
                         "content": f"message content {message_id}",
                         "reactions": [
@@ -2061,6 +2059,7 @@ class TestModel:
                         ],
                     }
                     for message_id, reactions in msgs
+                    if reactions is not None
                 }
             }
 
@@ -2082,7 +2081,7 @@ class TestModel:
         )
         model.index = reaction_event_index_factory(
             [
-                (unindexed_message_id, None),
+                (unindexed_message_id, None),  # explicitly exclude
                 (2, [(1, "unicode_emoji", "1232", "thumbs_up")]),
                 (3, []),
             ]