From 44274ad1c2958ce455426a8226b624563a5c2643 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 17 Feb 2025 11:44:02 +0000 Subject: [PATCH] builds: Check if watchers exist before adding this There is no elegant way to upsert here, so this is what it has to be for now. Signed-off-by: Michael Tremer --- src/buildservice/builds.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index 4a57a1b7..ab518c35 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -698,6 +698,13 @@ class Build(database.Base, database.BackendMixin, database.SoftDeleteMixin): """ Adds a watcher to this build """ + # Don't add the same watcher more than once + # SQLAlchemy does not have an elegant way to do an upsert here or to ignore + # and additional inserts, so we will have to check ourselves. Oh well. + if await self.watched_by(user): + return + + # Add the new watcher return await self.db.insert( BuildWatcher, build = self, -- 2.47.3