Repository: fedora-infra/bodhi

Issue:
Further comments on pushed updates with autopush disabled remove stable requests
 Andre Robatino [reported](https://bugzilla.redhat.com/show_bug.cgi?id=1380622) that Bodhi update stable requests are being reset by subsequent comments. For example, [this kernel update](https://bodhi.fedoraproject.org/updates/FEDORA-2016-7179af3ac1) was set to go to stable by labbott about 15 hours ago at the time of this writing. About 8 hours after that, another user helpfully gave the update a +1 and that comment caused the request for stable to be removed. The update now shows as status testing with no request.

I have not yet investigated the code to determine where the mistake in logic is.
# Known workaround

If you experience this issue on one of your updates, a possible workaround is to edit the update and turn autokarma on. After doing this, any additional +1 should trigger the update to push. You should also be able to push the update once it reaches 7 days.



Discussion:
I've lowered the priority due to discovering a workaround.

This is easily reproducible in staging:

https://bodhi.stg.fedoraproject.org/updates/FEDORA-2016-7179af3ac1

Which theoretically means it shouldn't be hard to fix!

The problem is in [this code](https://github.com/fedora-infra/bodhi/blob/2.2.3/bodhi/server/models/models.py#L1657-L1669):

```
                    if self.autokarma:
                        log.info("Automatically marking %s as stable" % self.title)
                        self.set_request(db, UpdateRequest.stable, agent)
                        self.request = UpdateRequest.stable
                        self.date_pushed = None
                        notifications.publish(
                            topic='update.karma.threshold.reach',
                            msg=dict(update=self, status='stable'))
                    else:
                        # Add the 'testing_approval_msg_based_on_karma' message now
                        log.info("%s update has reached the stable karma threshold and can be pushed to "\
                        "stable now if the maintainer wishes" % self.title)
                         self.request = None
```

This code causes any comment with karma on a non-autopushing update to set self.request to `None`, regardless of what the request is.


Resolving patch:
diff --git a/bodhi/server/models/models.py b/bodhi/server/models/models.py
--- a/bodhi/server/models/models.py
+++ b/bodhi/server/models/models.py
@@ -1697,7 +1697,6 @@ def check_karma_thresholds(self, db, agent):
                         # Add the 'testing_approval_msg_based_on_karma' message now
                         log.info("%s update has reached the stable karma threshold and can be pushed to "\
                         "stable now if the maintainer wishes" % self.title)
-                        self.request = None
                 elif self.unstable_karma not in (0, None) and self.karma <= self.unstable_karma:
                     log.info("Automatically unpushing %s" % self.title)
                     self.obsolete(db)


Test patch:
diff --git a/bodhi/tests/server/functional/test_updates.py b/bodhi/tests/server/functional/test_updates.py
--- a/bodhi/tests/server/functional/test_updates.py
+++ b/bodhi/tests/server/functional/test_updates.py
@@ -2900,14 +2900,17 @@ def test_manually_push_critical_update_with_negative_karma(self, publish, *args)
 
         self.assertEquals(up.karma, 3)
         self.assertEquals(up.autokarma, False)
+        # The request should still be at testing. This assertion tests for
+        # https://github.com/fedora-infra/bodhi/issues/989 where karma comments were resetting the
+        # request to None.
+        self.assertEquals(up.request, UpdateRequest.testing)
+        self.assertEquals(up.status, UpdateStatus.testing)
 
-        # Checks Push to Stable text in the html page for this update
         id = 'kernel-3.11.5-300.fc17'
         resp = self.app.get('/updates/%s' % id,
                             headers={'Accept': 'text/html'})
         self.assertIn('text/html', resp.headers['Content-Type'])
         self.assertIn(id, resp)
-        self.assertIn('Push to Stable', resp)
 
     @mock.patch(**mock_valid_requirements)
     @mock.patch('bodhi.server.notifications.publish')
@@ -2946,14 +2949,17 @@ def test_manually_push_critical_update_with_autopush_turned_off(self, publish, *
 
         self.assertEquals(up.karma, 3)
         self.assertEquals(up.autokarma, False)
+        # The request should still be at testing. This assertion tests for
+        # https://github.com/fedora-infra/bodhi/issues/989 where karma comments were resetting the
+        # request to None.
+        self.assertEquals(up.request, UpdateRequest.testing)
+        self.assertEquals(up.status, UpdateStatus.testing)
 
-        # Checks Push to Stable text in the html page for this update
         id = 'kernel-3.11.5-300.fc17'
         resp = self.app.get('/updates/%s' % id,
                             headers={'Accept': 'text/html'})
         self.assertIn('text/html', resp.headers['Content-Type'])
         self.assertIn(id, resp)
-        self.assertIn('Push to Stable', resp)
 
     @mock.patch(**mock_valid_requirements)
     @mock.patch('bodhi.server.notifications.publish')