From: Michael Tremer Date: Mon, 17 Oct 2022 15:37:57 +0000 (+0000) Subject: builds: Fix exception when trying to remove a user which is not a watcher X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04ade1050aba001fdb048781d691c4a105346c2b;p=pbs.git builds: Fix exception when trying to remove a user which is not a watcher Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 37e9acf6..e3535609 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -585,7 +585,10 @@ class Build(base.DataObject): ) # Remove from cache - self.watchers.remove(user) + try: + self.watchers.remove(user) + except KeyError: + pass def _add_watchers(self): """ diff --git a/tests/build.py b/tests/build.py index de159b24..baf97d65 100755 --- a/tests/build.py +++ b/tests/build.py @@ -60,6 +60,10 @@ class BuildTestCase(test.TestCase): with self.db.transaction(): build.remove_watcher(self.user) + # Remove the default user as watcher (again) + with self.db.transaction(): + build.remove_watcher(self.user) + # Check if the watcher has been removed self.assertNotIn(self.user, build.watchers)