Skip to content

Commit 64cd2e1

Browse files
mubarak-mustophatimabbott
authored andcommitted
bugfix: model: Avoid KeyError when reading user settings at startup.
Retrieve user settings from the `user_settings` object when it is present in `initial_data`. Many of these settings were removed from the top level object returned by `POST /register` in ZFL 439 (v12.0). Tests updated. Fixes #1600.
1 parent 8e5c035 commit 64cd2e1

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

tests/model/test_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ def test_init_user_settings(self, mocker, initial_data, sptn, expected_sptn_valu
126126
assert "user_settings" not in initial_data # we add it in tests
127127

128128
if sptn is not None:
129-
initial_data["user_settings"] = {"send_private_typing_notifications": sptn}
129+
initial_data["user_settings"] = {
130+
"send_private_typing_notifications": sptn,
131+
"twenty_four_hour_time": initial_data["twenty_four_hour_time"],
132+
"pm_content_in_desktop_notifications": initial_data[
133+
"pm_content_in_desktop_notifications"
134+
],
135+
}
130136

131137
mocker.patch(MODEL + ".get_messages", return_value="")
132138
self.client.register = mocker.Mock(return_value=initial_data)

zulipterminal/model.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,17 @@ def __init__(self, controller: Any) -> None:
235235
if user_settings is None
236236
else user_settings["send_private_typing_notifications"]
237237
), # ZFL 105, Zulip 5.0
238-
twenty_four_hour_time=self.initial_data["twenty_four_hour_time"],
239-
pm_content_in_desktop_notifications=self.initial_data[
240-
"pm_content_in_desktop_notifications"
241-
],
238+
# these settings were removed from the top-level object in ZFL 439 (v12.0)
239+
twenty_four_hour_time=(
240+
self.initial_data["twenty_four_hour_time"]
241+
if user_settings is None
242+
else user_settings["twenty_four_hour_time"]
243+
),
244+
pm_content_in_desktop_notifications=(
245+
self.initial_data["pm_content_in_desktop_notifications"]
246+
if user_settings is None
247+
else user_settings["pm_content_in_desktop_notifications"]
248+
),
242249
)
243250

244251
self.new_user_input = True

0 commit comments

Comments
 (0)