Repository: fedora-infra/bodhi

Issue:
After 5.7.3 release, some updates with bugzillas never finish loading
Cause of the issue is not yet known.

One such example: https://bodhi.fedoraproject.org/updates/FEDORA-2021-c2b61f2725

Currently investigating.

Will @mattiaverga have some idea?


Discussion:
Running in bodhi-shell:
```
u = m.Update.query.filter_by(alias='FEDORA-2021-c2b61f2725').one()
[b.update_details() for b in u.bugs]
m.Session().commit()
```

did manually fix the issue. This could suggest problem is somewhere in celery-worker?
@AdamSaleh yeah, I know the cause: creating sidetag rawhide updates never calls the work_on_bugs celery task.
We should find an appropriate place where to call the task for this type of updates, like we do for the other, or we can find a place where to call it for all types (maybe in the update.__init__() method, which I think it's the only common place for all).

This has been on my todo list for a while, but always postponed since it's not causing any real issue apart of the missing title in the web UI (the loading animation is just a gif, nothing is really loading in the background).
Good! I will mention it to releng guys, that this shouldn't signify an issue, more of a UX problem.

I wonder if we should have such hook directly in the model somewhere? Or is that a bad idea?

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2417,6 +2417,16 @@ def new(cls, request, data):
         log.debug(f"Triggering db commit for new update {up.alias}.")
         db.commit()
 
+        log.info("Deferring working on bugs and fetching test cases to celery")
+        alias = up.alias
+        if not bool(config.get('bodhi_email')):
+            log.warning("Not configured to handle bugs")
+        else:
+            bug_ids = [bug.bug_id for bug in up.bugs]
+            work_on_bugs_task.delay(alias, bug_ids)
+
+        fetch_test_cases_task.delay(alias)
+
         # track whether to set gating status shortly...
         setgs = config.get('test_gating.required')
         # The request to testing for side-tag updates is set within the signed consumer
@@ -3051,9 +3061,6 @@ def set_request(self, db, action, username):
             )
         self.comment(db, comment_text, author=u'bodhi')
 
-        # Store the update alias so Celery doesn't have to emit SQL
-        alias = self.alias
-
         action_message_map = {
             UpdateRequest.revoke: update_schemas.UpdateRequestRevokeV1,
             UpdateRequest.stable: update_schemas.UpdateRequestStableV1,
@@ -3072,15 +3079,6 @@ def set_request(self, db, action, username):
                 self.update_test_gating_status()
                 db.commit()
 
-            log.info("Deferring working on bugs and fetching test cases to celery")
-            if not bool(config.get('bodhi_email')):
-                log.warning("Not configured to handle bugs")
-            else:
-                bugs = [bug.bug_id for bug in self.bugs]
-                work_on_bugs_task.delay(alias, bugs)
-
-            fetch_test_cases_task.delay(alias)
-
     def waive_test_results(self, username, comment=None, tests=None):
         """
         Attempt to waive test results for this update.


Test patch:
diff --git a/bodhi/tests/server/test_models.py b/bodhi/tests/server/test_models.py
--- a/bodhi/tests/server/test_models.py
+++ b/bodhi/tests/server/test_models.py
@@ -1909,6 +1909,34 @@ def test_release_missing(self):
         assert str(exc.value) == 'You must specify a Release when creating an Update.'
 
 
+@mock.patch('bodhi.server.models.work_on_bugs_task', mock.Mock())
+@mock.patch('bodhi.server.models.fetch_test_cases_task', mock.Mock())
+class TestUpdateNew(BasePyTestCase):
+    """Tests for the Update.new() method."""
+
+    @mock.patch.dict('bodhi.server.config.config', {'bodhi_email': None})
+    @mock.patch('bodhi.server.models.log.warning')
+    def test_add_bugs_bodhi_not_configured(self, warning):
+        """Adding a bug should log a warning if Bodhi isn't configured to handle bugs."""
+        release = self.create_release('36')
+        package = model.RpmPackage.query.filter_by(name='bodhi').one()
+        build = model.RpmBuild(nvr='bodhi-6.0.0-1.fc36', release=release,
+                               package=package, signed=False)
+        self.db.add(build)
+        data = {'release': release, 'builds': [build], 'from_tag': 'f36-build-side-1234',
+                'bugs': [], 'requirements': '', 'edited': '', 'autotime': True,
+                'stable_days': 3, 'stable_karma': 3, 'unstable_karma': -1,
+                'notes': 'simple update', 'type': 'unspecified'}
+        request = mock.MagicMock()
+        request.db = self.db
+        request.user.name = 'tester'
+        self.db.flush()
+
+        model.Update.new(request, data)
+
+        warning.assert_called_with('Not configured to handle bugs')
+
+
 @mock.patch('bodhi.server.models.work_on_bugs_task', mock.Mock())
 @mock.patch('bodhi.server.models.fetch_test_cases_task', mock.Mock())
 class TestUpdateEdit(BasePyTestCase):
@@ -3907,22 +3935,6 @@ def test_set_request_pending_testing_gating_true(self):
         assert self.obj.request == UpdateRequest.testing
         assert self.obj.test_gating_status == TestGatingStatus.failed
 
-    @mock.patch.dict('bodhi.server.config.config', {'bodhi_email': None})
-    @mock.patch('bodhi.server.models.log.warning')
-    def test_add_bugs_bodhi_not_configured(self, warning):
-        """Adding a bug should log a warning if Bodhi isn't configured to handle bugs."""
-        req = DummyRequest(user=DummyUser())
-        req.errors = cornice.Errors()
-        req.koji = buildsys.get_session()
-        self.obj.request = None
-        self.obj.test_gating_status = None
-        assert self.obj.status == UpdateStatus.pending
-
-        with mock_sends(Message):
-            self.obj.set_request(self.db, UpdateRequest.testing, req.user.name)
-
-        warning.assert_called_with('Not configured to handle bugs')
-
     def test_set_request_pending_stable(self):
         """Ensure that we can submit an update to stable if it is pending and has enough karma."""
         req = DummyRequest(user=DummyUser())