From 2644e6d8b0bdaf4e842d35db0cfa5987f905af1c Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 11 Jul 2020 17:11:04 -0400 Subject: [PATCH] Fix account update method for unasaved accounts If the account passed to `saved_accounts.update()` doesn't exist in the config file, return instead of failing with a KeyError. An account can be absent from the file if "Remember my account" was unchecked on login, or if the file hasn't been updated yet on disk after login (race condition). --- TODO.md | 2 ++ src/backend/user_files.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 1c1a0477..dac504a6 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,7 @@ # TODO +- fix device section headers when members pane is small +- when promiting someone in room as admin, rank isn't updated in members list - save and restore status in accounts.json - mark accounts as offline when closing mirage - document new x11 dependnecy (auto-idle) diff --git a/src/backend/user_files.py b/src/backend/user_files.py index e2e71560..ae5690e9 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -206,10 +206,13 @@ class Accounts(JSONDataFile): presence: Optional[str] = None, order: Optional[int] = None, ) -> None: - """Update existing account in the config and write to disk.""" + """Update an account if found in the config file and write to disk.""" saved = await self.read() + if user_id not in saved: + return + if enabled is not None: saved[user_id]["enabled"] = enabled