Blob Blame History Raw
From 5da6aaaf240d6cf7b9f39104254701daa1b0ac65 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Wed, 13 Nov 2019 20:39:22 +0100
Subject: [PATCH] Fix builds being signed without being part of an update

@nirik reported to us that bodhi sends an error message when it
encounters a build that is signed but is not part of an update.
This commit should help preventing the traceback.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
---
 bodhi/server/consumers/signed.py            |  6 ++++--
 bodhi/tests/server/consumers/test_signed.py | 11 +++++++++++
 news/3720.bug                               |  1 +
 3 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 news/3720.bug

diff --git a/bodhi/server/consumers/signed.py b/bodhi/server/consumers/signed.py
index ecb6891e6..abbbedefe 100644
--- a/bodhi/server/consumers/signed.py
+++ b/bodhi/server/consumers/signed.py
@@ -89,7 +89,7 @@ def __call__(self, message: fedora_messaging.api.Message):
                 log.info('Build is not assigned to release, skipping')
                 return
 
-            if build.update.from_tag:
+            if build.update and build.update.from_tag:
                 koji_testing_tag = build.release.get_testing_side_tag(build.update.from_tag)
                 if tag != koji_testing_tag:
                     log.info("Tag is not testing side tag, skipping")
@@ -112,7 +112,9 @@ def __call__(self, message: fedora_messaging.api.Message):
             log.info("Build %s has been marked as signed" % build_nvr)
 
             # If every build in update is signed change status to testing
-            if not build.update.release.composed_by_bodhi and build.update.signed:
+            if build.update \
+                    and not build.update.release.composed_by_bodhi \
+                    and build.update.signed:
                 log.info("Every build in update is signed, set status to testing")
 
                 build.update.status = UpdateStatus.testing
diff --git a/bodhi/tests/server/consumers/test_signed.py b/bodhi/tests/server/consumers/test_signed.py
index 261b34c78..3bbc71fe8 100644
--- a/bodhi/tests/server/consumers/test_signed.py
+++ b/bodhi/tests/server/consumers/test_signed.py
@@ -77,6 +77,17 @@ def test_consume(self, mock_build_model):
         self.handler(self.sample_message)
         assert build.signed is True
 
+    @mock.patch('bodhi.server.consumers.signed.Build')
+    def test_consume_build_with_no_update(self, mock_build_model):
+        """Assert that messages marking the build as signed updates the database"""
+        build = mock_build_model.get.return_value
+        build.signed = False
+        build.update = None
+        build.release.pending_testing_tag = self.sample_message.body["tag"]
+
+        self.handler(self.sample_message)
+        assert build.signed is True
+
     @mock.patch('bodhi.server.consumers.signed.Build')
     def test_consume_not_pending_testing_tag(self, mock_build_model):
         """
diff --git a/news/3720.bug b/news/3720.bug
new file mode 100644
index 000000000..02de5a8c8
--- /dev/null
+++ b/news/3720.bug
@@ -0,0 +1 @@
+Fix the traceback when builds are being signed without being included in an update