Repository: fedora-infra/bodhi

Issue:
Disabling autokarma (still) removes the karma thresholds
Whenever I edit an update to disable autokarma (I have to edit it, as opposed to just unchecking the box from the beginning, due to issue #1032), the thresholds vanish. The only way to get the thresholds back is to enable autokarma. As a result, the improvement from issue #772 (manual push to stable based on karma) does not work: if I disable autokarma, it does not work because the thresholds are deleted (which is clearly a bug); if I enable autokarma, it does not work because the button explicitly gets disabled if autokarma is enabled for some reason. (Why? It can be valid to trigger a manual push based on karma even if autokarma is enabled, because, if the update already had a karma of +1 and I set the autokarma threshold to +1, the automatic push will not trigger.)



Discussion:
I believe this is likely a UI issue, in either form rendering or processing (or both). As a workaround, I believe the CLI can be used to do this.

It's in the processing, not in the rendering. I did the query using the Python API, it clearly shows that stable_karma=None on the updates I disabled autokarma for using the web UI, so it was already incorrectly saved.
And no, the CLI can NOT be used for this, see #1125.
2 months and this showstopper is STILL not fixed.
Counting also #772, it has been almost 11 months that manual push to stable based on karma has no longer worked. Why is it taking so long to fix such a major issue? This is breaking the best-practice workflow for filing Fedora updates and encouraging people to just enable autokarma, with all the issues this entails (broken upgrade paths, updates being pushed after gaining karma too quickly with negative feedback either coming too late or being outvoted, etc.).
I found the cause of this bug:

https://github.com/fedora-infra/bodhi/blob/2.4.0/bodhi/server/models/models.py#L897-L898

I think we can just drop those two lines of code, write a test, and it will be fixed.
@dustymabe has also confirmed this issue. I am working on the fix. 

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -1008,14 +1008,6 @@ def edit(cls, request, data):
         if req is not None:
             up.set_request(db, req, request.user.name)
 
-        if not data['autokarma']:
-            data['stable_karma'] = None
-            data['unstable_karma'] = None
-            caveats.append({
-                'name': 'autokarma',
-                'description': 'Auto-karma requests disabled.',
-            })
-
         for key, value in data.items():
             setattr(up, key, value)
 


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -2606,8 +2606,8 @@ def test_edit_update_and_disable_features(self, publish, *args):
 
         self.assertEquals(up['require_bugs'], True)
         self.assertEquals(up['require_testcases'], False)
-        self.assertEquals(up['stable_karma'], None)
-        self.assertEquals(up['unstable_karma'], None)
+        self.assertEquals(up['stable_karma'], 3)
+        self.assertEquals(up['unstable_karma'], -3)
 
     @mock.patch(**mock_valid_requirements)
     @mock.patch('bodhi.server.notifications.publish')
@@ -2892,6 +2892,45 @@ def test__composite_karma_with_no_feedback(self, publish, *args):
         up = self.db.query(Update).filter_by(title=nvr).one()
         self.assertEqual(up._composite_karma, (0, 0))
 
+    @mock.patch(**mock_valid_requirements)
+    @mock.patch('bodhi.server.notifications.publish')
+    def test_karma_threshold_with_disabled_autopush(self, publish, *args):
+        """Ensure Karma threshold field is not None when Autopush is disabled."""
+        build = u'bodhi-2.0.0-2.fc17'
+        args = self.get_update(build)
+        args['autokarma'] = False
+        args['stable_karma'] = 3
+        args['unstable_karma'] = -3
+        r = self.app.post_json('/updates/', args)
+        publish.assert_called_with(topic='update.request.testing', msg=ANY)
+
+        up = r.json_body
+        self.assertEquals(up['autokarma'], False)
+        self.assertEquals(up['stable_karma'], 3)
+        self.assertEquals(up['unstable_karma'], -3)
+
+        # Pretend it was pushed to testing
+        update = self.db.query(Update).filter_by(title=build).one()
+        update.request = None
+        update.status = UpdateStatus.testing
+        update.pushed = True
+        self.db.flush()
+
+        # Mark it as testing
+        args['edited'] = args['builds']
+
+        # Change Karma Thresholds
+        args['stable_karma'] = 4
+        args['unstable_karma'] = -4
+
+        r = self.app.post_json('/updates/', args)
+        up = r.json_body
+        self.assertEquals(up['status'], u'testing')
+        self.assertEquals(up['request'], None)
+        self.assertEquals(up['autokarma'], False)
+        self.assertEquals(up['stable_karma'], 4)
+        self.assertEquals(up['unstable_karma'], -4)
+
     @mock.patch(**mock_valid_requirements)
     @mock.patch('bodhi.server.notifications.publish')
     def test_disable_autopush_for_critical_updates(self, publish, *args):