Repository: fedora-infra/bodhi

Issue:
New comment causes bodhi to resubmit for batched after submitting for stable
See https://bodhi.fedoraproject.org/updates/FEDORA-2017-1db64016e9 . Bodhi submitted this for batched, then for stable when the necessary time was reached. A +1 comment after that caused Bodhi to immediately submit it for batched again.


Discussion:
Thanks for the report - I've found the problem. Fix incoming.

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2374,9 +2374,10 @@ def check_karma_thresholds(self, db, agent):
                     log.info("Automatically marking %s as stable" % self.title)
                     self.set_request(db, UpdateRequest.stable, agent)
                 else:
-                    log.info("Automatically adding %s to batch of updates that will be pushed to"
-                             " stable at a later date" % self.title)
-                    self.set_request(db, UpdateRequest.batched, agent)
+                    if self.request not in (UpdateRequest.batched, UpdateRequest.stable):
+                        log.info("Automatically adding %s to batch of updates that will be pushed "
+                                 "to stable at a later date" % self.title)
+                        self.set_request(db, UpdateRequest.batched, agent)
 
                 self.date_pushed = None
                 notifications.publish(
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -53,7 +53,7 @@
 # The short X.Y version.
 version = '2.12'
 # The full version, including alpha/beta/rc tags.
-release = '2.12.1'
+release = '2.12.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@ def get_requirements(requirements_file='requirements.txt'):
 
 here = os.path.abspath(os.path.dirname(__file__))
 README = open(os.path.join(here, 'README.rst')).read()
-VERSION = '2.12.1'
+VERSION = '2.12.2'
 # Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers
 CLASSIFIERS = [
     'Development Status :: 5 - Production/Stable',


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
@@ -1580,6 +1580,29 @@ def test_stable_karma(self, publish):
         self.assertEqual(update.request, UpdateRequest.batched)
         publish.assert_called_with(topic='update.comment', msg=mock.ANY)
 
+    @mock.patch('bodhi.server.notifications.publish')
+    def test_karma_on_stable_request_does_not_set_to_batched(self, publish):
+        """
+        Ensure that adding karma to an update that is going stable doesn't send it back to batched.
+
+        https://github.com/fedora-infra/bodhi/issues/1881
+        """
+        update = self.obj
+        update.request = None
+        update.status = UpdateStatus.testing
+        update.comment(self.db, u"foo", 1, u'foo')
+        update.comment(self.db, u"foo", 1, u'bar')
+        update.comment(self.db, u"foo", 1, u'biz')
+        self.assertEqual(update.request, UpdateRequest.batched)
+        # Simulate the stable cron job having run.
+        update.request = UpdateRequest.stable
+
+        update.comment(self.db, u"dont go back to batched!", 1, u'bowlofeggs')
+
+        # The update should stay at stable, rather than being set back to batched.
+        self.assertEqual(update.request, UpdateRequest.stable)
+        publish.assert_called_with(topic='update.comment', msg=mock.ANY)
+
     @mock.patch('bodhi.server.notifications.publish')
     def test_unstable_karma(self, publish):
         update = self.obj