Repository: fedora-infra/bodhi

Issue:
Sometimes automatic updates miss changelog
For unknown reason, sometimes Koji is reporting empty rpm headers, so the automatic updates are missing the changelog and bugs aren't attached.

This seems the same cause of https://github.com/fedora-infra/bodhi/issues/4146

I've opened a ticket to Koji to try to find the root cause https://pagure.io/koji/issue/3178


Discussion:

Resolving patch:
diff --git a/bodhi/server/consumers/automatic_updates.py b/bodhi/server/consumers/automatic_updates.py
--- a/bodhi/server/consumers/automatic_updates.py
+++ b/bodhi/server/consumers/automatic_updates.py
@@ -22,6 +22,7 @@
 tagged with certain tags.
 """
 
+from time import sleep
 import logging
 import re
 
@@ -148,10 +149,13 @@ def __call__(self, message: fedora_messaging.api.Message) -> None:
             log.debug(f"Creating new update for {bnvr}.")
             try:
                 changelog = build.get_changelog(lastupdate=True)
-            except ValueError:
+            except ValueError as e:
                 # Often due to bot-generated builds
-                # https://github.com/fedora-infra/bodhi/issues/4146
-                changelog = None
+                # https://pagure.io/koji/issue/3178
+                log.warning(str(e))
+                sleep(5)
+                # Re-raise exception, so that the message can be re-queued
+                raise
             except Exception:
                 # Re-raise exception, so that the message can be re-queued
                 raise


Test patch:
diff --git a/bodhi/tests/server/consumers/test_automatic_updates.py b/bodhi/tests/server/consumers/test_automatic_updates.py
--- a/bodhi/tests/server/consumers/test_automatic_updates.py
+++ b/bodhi/tests/server/consumers/test_automatic_updates.py
@@ -187,20 +187,17 @@ def test_bug_not_added_excluded_release(self, mock_generate_changelog):
 ```"""
         assert len(update.bugs) == 0
 
+    @mock.patch('bodhi.server.consumers.automatic_updates.log.warning')
+    @mock.patch('bodhi.server.consumers.automatic_updates.sleep')
     @mock.patch('bodhi.server.models.RpmBuild.get_changelog')
-    def test_changelog_handled_exception(self, mock_generate_changelog):
-        """Assert that update creation is succesful if get_changelog() raises ValueError."""
+    def test_changelog_handled_exception(self, mock_generate_changelog, sleep, warning):
+        """Assert that update creation is not successful if get_changelog() raises ValueError."""
         mock_generate_changelog.side_effect = ValueError('Handled exception')
-
-        # process the message
-        self.handler(self.sample_message)
-
-        # check if the update exists...
-        update = self.db.query(Update).filter(
-            Update.builds.any(Build.nvr == self.sample_nvr)
-        ).first()
-
-        assert update.notes == "Automatic update for colord-1.3.4-1.fc26."
+        with pytest.raises(ValueError) as exc:
+            self.handler(self.sample_message)
+        assert str(exc.value) == 'Handled exception'
+        sleep.assert_called_once_with(5)
+        warning.assert_called_once_with('Handled exception')
 
     @mock.patch('bodhi.server.models.RpmBuild.get_changelog')
     def test_changelog_unhandled_exception(self, mock_generate_changelog):