prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  bodhi-dequqe-stable dies if any update in the queue is no longer eligible to go stable
  QuLogic from Freenode reported today that batched updates didn't go stable at 03:00 UTC like they should have. I confirmed that the cron job ran, but I didn't see any notes about its output. I then ran the command by hand and received this output:
  
  ```
  [bowlofeggs@bodhi-backend01 ~][PROD]$ sudo -u apache /usr/bin/bodhi-dequeue-stable
  No handlers could be found for logger "bodhi.server"
  This update has not yet met the minimum testing requirements defined in the <a href="https://fedoraproject.org/wiki/Package_update_acceptance_criteria">Package Update Acceptance Criteria</a>
  ```
  
  The [```dequeue_stable()```](https://github.com/fedora-infra/bodhi/blob/3.0.0/bodhi/server/scripts/dequeue_stable.py#L28-L46) function runs a large transaction with only a single try/except. It seems that some update in the queue no longer meets testing requirements (probably due to receiving a -1 karma after going to batched) and is raising an Exception when the tool attempts to mark it for stable. Since there is only one try/except handler, this causes the whole transaction to be rolled back.
  
  It should be easy to fix this - we just need a try/except around each update.
  
  Thanks to QuLogic from Freenode for reporting this issue to me.
  
  </issue>
  <code>
  [start of bodhi/server/scripts/dequeue_stable.py]
  1 # -*- coding: utf-8 -*-
  2 # Copyright © 2017 Caleigh Runge-Hottman
  3 #
  4 # This file is part of Bodhi.
  5 #
  6 # This program is free software; you can redistribute it and/or
  7 # modify it under the terms of the GNU General Public License
  8 # as published by the Free Software Foundation; either version 2
  9 # of the License, or (at your option) any later version.
  10 #
  11 # This program is distributed in the hope that it will be useful,
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 # GNU General Public License for more details.
  15 #
  16 # You should have received a copy of the GNU General Public License
  17 # along with this program; if not, write to the Free Software
  18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19 """This script is responsible for moving all updates with a batched request to a stable request."""
  20 
  21 import sys
  22 
  23 import click
  24 
  25 from bodhi.server import buildsys, config, models, Session, initialize_db
  26 
  27 
  28 @click.command()
  29 @click.version_option(message='%(version)s')
  30 def dequeue_stable():
  31     """Convert all batched requests to stable requests."""
  32     initialize_db(config.config)
  33     buildsys.setup_buildsystem(config.config)
  34     db = Session()
  35 
  36     try:
  37         batched = db.query(models.Update).filter_by(request=models.UpdateRequest.batched).all()
  38         for update in batched:
  39             update.set_request(db, models.UpdateRequest.stable, u'bodhi')
  40         db.commit()
  41 
  42     except Exception as e:
  43         print(str(e))
  44         db.rollback()
  45         Session.remove()
  46         sys.exit(1)
  47
  [end of bodhi/server/scripts/dequeue_stable.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/bodhi/server/scripts/dequeue_stable.py b/bodhi/server/scripts/dequeue_stable.py
  --- a/bodhi/server/scripts/dequeue_stable.py
  +++ b/bodhi/server/scripts/dequeue_stable.py
  @@ -1,5 +1,5 @@
   # -*- coding: utf-8 -*-
  -# Copyright © 2017 Caleigh Runge-Hottman
  +# Copyright © 2017 Caleigh Runge-Hottman and Red Hat, Inc.
   #
   # This file is part of Bodhi.
   #
  @@ -36,11 +36,17 @@
       try:
           batched = db.query(models.Update).filter_by(request=models.UpdateRequest.batched).all()
           for update in batched:
  -            update.set_request(db, models.UpdateRequest.stable, u'bodhi')
  -        db.commit()
  -
  +            try:
  +                update.set_request(db, models.UpdateRequest.stable, u'bodhi')
  +                db.commit()
  +            except Exception as e:
  +                print('Unable to stabilize {}: {}'.format(update.alias, str(e)))
  +                db.rollback()
  +                msg = u"Bodhi is unable to request this update for stabilization: {}"
  +                update.comment(db, msg.format(str(e)), author=u'bodhi')
  +                db.commit()
       except Exception as e:
           print(str(e))
  -        db.rollback()
  -        Session.remove()
           sys.exit(1)
  +    finally:
  +        Session.remove()
  
verification_info: {"golden_diff": "diff --git a/bodhi/server/scripts/dequeue_stable.py b/bodhi/server/scripts/dequeue_stable.py\n--- a/bodhi/server/scripts/dequeue_stable.py\n+++ b/bodhi/server/scripts/dequeue_stable.py\n@@ -1,5 +1,5 @@\n # -*- coding: utf-8 -*-\n-# Copyright \u00a9 2017 Caleigh Runge-Hottman\n+# Copyright \u00a9 2017 Caleigh Runge-Hottman and Red Hat, Inc.\n #\n # This file is part of Bodhi.\n #\n@@ -36,11 +36,17 @@\n     try:\n         batched = db.query(models.Update).filter_by(request=models.UpdateRequest.batched).all()\n         for update in batched:\n-            update.set_request(db, models.UpdateRequest.stable, u'bodhi')\n-        db.commit()\n-\n+            try:\n+                update.set_request(db, models.UpdateRequest.stable, u'bodhi')\n+                db.commit()\n+            except Exception as e:\n+                print('Unable to stabilize {}: {}'.format(update.alias, str(e)))\n+                db.rollback()\n+                msg = u\"Bodhi is unable to request this update for stabilization: {}\"\n+                update.comment(db, msg.format(str(e)), author=u'bodhi')\n+                db.commit()\n     except Exception as e:\n         print(str(e))\n-        db.rollback()\n-        Session.remove()\n         sys.exit(1)\n+    finally:\n+        Session.remove()\n", "issue": "bodhi-dequqe-stable dies if any update in the queue is no longer eligible to go stable\nQuLogic from Freenode reported today that batched updates didn't go stable at 03:00 UTC like they should have. I confirmed that the cron job ran, but I didn't see any notes about its output. I then ran the command by hand and received this output:\r\n\r\n```\r\n[bowlofeggs@bodhi-backend01 ~][PROD]$ sudo -u apache /usr/bin/bodhi-dequeue-stable\r\nNo handlers could be found for logger \"bodhi.server\"\r\nThis update has not yet met the minimum testing requirements defined in the <a href=\"https://fedoraproject.org/wiki/Package_update_acceptance_criteria\">Package Update Acceptance Criteria</a>\r\n```\r\n\r\nThe [```dequeue_stable()```](https://github.com/fedora-infra/bodhi/blob/3.0.0/bodhi/server/scripts/dequeue_stable.py#L28-L46) function runs a large transaction with only a single try/except. It seems that some update in the queue no longer meets testing requirements (probably due to receiving a -1 karma after going to batched) and is raising an Exception when the tool attempts to mark it for stable. Since there is only one try/except handler, this causes the whole transaction to be rolled back.\r\n\r\nIt should be easy to fix this - we just need a try/except around each update.\r\n\r\nThanks to QuLogic from Freenode for reporting this issue to me.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright \u00a9 2017 Caleigh Runge-Hottman\n#\n# This file is part of Bodhi.\n#\n# This program is free software; you can redistribute it and/or\n# modify it under the terms of the GNU General Public License\n# as published by the Free Software Foundation; either version 2\n# of the License, or (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, write to the Free Software\n# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n\"\"\"This script is responsible for moving all updates with a batched request to a stable request.\"\"\"\n\nimport sys\n\nimport click\n\nfrom bodhi.server import buildsys, config, models, Session, initialize_db\n\n\n@click.command()\n@click.version_option(message='%(version)s')\ndef dequeue_stable():\n    \"\"\"Convert all batched requests to stable requests.\"\"\"\n    initialize_db(config.config)\n    buildsys.setup_buildsystem(config.config)\n    db = Session()\n\n    try:\n        batched = db.query(models.Update).filter_by(request=models.UpdateRequest.batched).all()\n        for update in batched:\n            update.set_request(db, models.UpdateRequest.stable, u'bodhi')\n        db.commit()\n\n    except Exception as e:\n        print(str(e))\n        db.rollback()\n        Session.remove()\n        sys.exit(1)\n", "path": "bodhi/server/scripts/dequeue_stable.py"}]}