We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bodhi.server.consumers.updates.UpdatesHandler.consumer uses an assert statement
```assert``` statements get removed from optimized code, which is what gets built in Koji (which is where production Bodhi builds come from). Thus, the assertion will not be present in production.

If the assertion is important, we should either reconcile the database discrepancy, or raise an Exception. It might make the most sense to reconcile the database discrepancy.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bodhi/server/consumers/updates.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Copyright 2015-2018 Red Hat Inc., and others.
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 along with
17 # this program; if not, write to the Free Software Foundation, Inc., 51
18 # Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 """
20 The "updates handler".
21 
22 This module is responsible for doing value-added work "offline" that used to be
23 done when updates were submitted.  Specifically, when someone submits an update
24 we used to:
25 
26 - Update any bugs in bugzilla associated with the update.
27 - Check for test cases in the wiki.
28 
29 Those things could sometimes take a *very* long time, especially if there were
30 lots of builds and lots of bugs in the update.
31 
32 Now, update-submission breezes by those steps and simply tells the user "OK".
33 A fedmsg message gets published when their update goes through, and *that*
34 message gets received here and triggers us to do all that network-laden heavy
35 lifting.
36 """
37 
38 import logging
39 import pprint
40 import time
41 
42 import fedmsg.consumers
43 
44 from bodhi.server import initialize_db, util, bugs as bug_module
45 from bodhi.server.config import config
46 from bodhi.server.exceptions import BodhiException
47 from bodhi.server.models import Bug, Update, UpdateType
48 
49 
50 log = logging.getLogger('bodhi')
51 
52 
53 class UpdatesHandler(fedmsg.consumers.FedmsgConsumer):
54     """
55     Perform background tasks when updates are created or edited.
56 
57     This fedmsg listener waits for messages from the frontend about new or edited updates, and
58     performs background tasks such as modifying Bugzilla issues (and loading information from
59     Bugzilla so we can display it to the user) and looking up wiki test cases.
60 
61     Attributes:
62         db_factory (bodhi.server.util.TransactionalSessionMaker): A context manager that yields a
63             database session.
64         handle_bugs (bool): If True, interact with Bugzilla. Else do not.
65         topic (list): A list of strings that indicate which fedmsg topics this consumer listens to.
66     """
67 
68     config_key = 'updates_handler'
69 
70     def __init__(self, hub, *args, **kwargs):
71         """
72         Initialize the UpdatesHandler, subscribing it to the appropriate topics.
73 
74         Args:
75             hub (moksha.hub.hub.CentralMokshaHub): The hub this handler is consuming messages from.
76                 It is used to look up the hub config.
77         """
78         initialize_db(config)
79         self.db_factory = util.transactional_session_maker()
80 
81         prefix = hub.config.get('topic_prefix')
82         env = hub.config.get('environment')
83         self.topic = [
84             prefix + '.' + env + '.bodhi.update.request.testing',
85             prefix + '.' + env + '.bodhi.update.edit',
86         ]
87 
88         self.handle_bugs = bool(config.get('bodhi_email'))
89         if not self.handle_bugs:
90             log.warning("No bodhi_email defined; not fetching bug details")
91         else:
92             bug_module.set_bugtracker()
93 
94         super(UpdatesHandler, self).__init__(hub, *args, **kwargs)
95         log.info('Bodhi updates handler listening on:\n'
96                  '%s' % pprint.pformat(self.topic))
97 
98     def consume(self, message):
99         """
100         Process the given message, updating relevant bugs and test cases.
101 
102         Args:
103             message (munch.Munch): A fedmsg about a new or edited update.
104         """
105         msg = message['body']['msg']
106         topic = message['topic']
107         alias = msg['update'].get('alias')
108 
109         log.info("Updates Handler handling  %s, %s" % (alias, topic))
110 
111         # Go to sleep for a second to try and avoid a race condition
112         # https://github.com/fedora-infra/bodhi/issues/458
113         time.sleep(1)
114 
115         if not alias:
116             log.error("Update Handler got update with no "
117                       "alias %s." % pprint.pformat(msg))
118             return
119 
120         with self.db_factory() as session:
121             update = Update.get(alias)
122             if not update:
123                 raise BodhiException("Couldn't find alias '%s' in DB" % alias)
124 
125             if topic.endswith('update.edit'):
126                 bugs = [Bug.get(idx) for idx in msg['new_bugs']]
127                 # Sanity check
128                 for bug in bugs:
129                     assert bug in update.bugs
130             elif topic.endswith('update.request.testing'):
131                 bugs = update.bugs
132             else:
133                 raise NotImplementedError("Should never get here.")
134 
135             self.work_on_bugs(session, update, bugs)
136             self.fetch_test_cases(session, update)
137 
138         if config['test_gating.required']:
139             with self.db_factory() as session:
140                 update = Update.get(alias)
141                 update.update_test_gating_status()
142 
143         log.info("Updates Handler done with %s, %s" % (alias, topic))
144 
145     def fetch_test_cases(self, session, update):
146         """
147         Query the wiki for test cases for each package on the given update.
148 
149         Args:
150             session (sqlalchemy.orm.session.Session): A database session.
151             update (bodhi.server.models.Update): The update's builds are iterated upon to find test
152                 cases for their associated Packages..
153         """
154         for build in update.builds:
155             build.package.fetch_test_cases(session)
156 
157     def work_on_bugs(self, session, update, bugs):
158         """
159         Iterate the list of bugs, retrieving information from Bugzilla and modifying them.
160 
161         Iterate the given list of bugs associated with the given update. For each bug, retrieve
162         details from Bugzilla, comment on the bug to let watchers know about the update, and mark
163         the bug as MODIFIED. If the bug is a security issue, mark the update as a security update.
164 
165         If the bug is private, Bodhi can't retrieve any information, comment on it, or modify
166         it, so we just associate the bug id with the update and mark it to be private.
167 
168         If handle_bugs is not True, return and do nothing.
169 
170         Args:
171             session (sqlalchemy.orm.session.Session): A database session.
172             update (bodhi.server.models.Update): The update that the bugs are associated with.
173             bugs (list): A list of bodhi.server.models.Bug instances that we wish to act on.
174         """
175         if not self.handle_bugs:
176             log.warning("Not configured to handle bugs")
177             return
178 
179         log.info("Got %i bugs to sync for %r" % (len(bugs), update.alias))
180         for bug in bugs:
181             log.info("Getting RHBZ bug %r" % bug.bug_id)
182             try:
183                 rhbz_bug = bug_module.bugtracker.getbug(bug.bug_id)
184 
185                 log.info("Updating our details for %r" % bug.bug_id)
186                 bug.update_details(rhbz_bug)
187                 if bug.private:
188                     # Bodhi can't retrieve any information so just continue with the next bug
189                     log.info("  Skipping bug %r because it is private" % (bug.bug_id))
190                     continue
191                 log.info("  Got title %r for %r" % (bug.title, bug.bug_id))
192 
193                 # If you set the type of your update to 'enhancement' but you
194                 # attach a security bug, we automatically change the type of your
195                 # update to 'security'. We need to do this first, so we don't
196                 # accidentally comment on stuff that we shouldn't.
197                 if bug.security:
198                     log.info("Setting our UpdateType to security.")
199                     update.type = UpdateType.security
200 
201                 log.info("Commenting on %r" % bug.bug_id)
202                 comment = config['initial_bug_msg'] % (
203                     update.title, update.release.long_name, update.abs_url())
204 
205                 log.info("Modifying %r" % bug.bug_id)
206                 bug.modified(update, comment)
207             except Exception:
208                 log.warning('Error occurred during updating single bug', exc_info=True)
209
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bodhi/server/consumers/updates.py b/bodhi/server/consumers/updates.py
--- a/bodhi/server/consumers/updates.py
+++ b/bodhi/server/consumers/updates.py
@@ -122,11 +122,21 @@
             if not update:
                 raise BodhiException("Couldn't find alias '%s' in DB" % alias)
 
+            bugs = []
             if topic.endswith('update.edit'):
-                bugs = [Bug.get(idx) for idx in msg['new_bugs']]
-                # Sanity check
-                for bug in bugs:
-                    assert bug in update.bugs
+                for idx in msg['new_bugs']:
+                    bug = Bug.get(idx)
+
+                    # Sanity check
+                    if bug is None or bug not in update.bugs:
+                        update_bugs_ids = [b.bug_id for b in update.bugs]
+                        update.update_bugs(update_bugs_ids + [idx], session)
+
+                        # Now, after update.update_bugs, bug with idx should exists in DB
+                        bug = Bug.get(idx)
+
+                    bugs.append(bug)
+
             elif topic.endswith('update.request.testing'):
                 bugs = update.bugs
             else:

{"golden_diff": "diff --git a/bodhi/server/consumers/updates.py b/bodhi/server/consumers/updates.py\n--- a/bodhi/server/consumers/updates.py\n+++ b/bodhi/server/consumers/updates.py\n@@ -122,11 +122,21 @@\n             if not update:\n                 raise BodhiException(\"Couldn't find alias '%s' in DB\" % alias)\n \n+            bugs = []\n             if topic.endswith('update.edit'):\n-                bugs = [Bug.get(idx) for idx in msg['new_bugs']]\n-                # Sanity check\n-                for bug in bugs:\n-                    assert bug in update.bugs\n+                for idx in msg['new_bugs']:\n+                    bug = Bug.get(idx)\n+\n+                    # Sanity check\n+                    if bug is None or bug not in update.bugs:\n+                        update_bugs_ids = [b.bug_id for b in update.bugs]\n+                        update.update_bugs(update_bugs_ids + [idx], session)\n+\n+                        # Now, after update.update_bugs, bug with idx should exists in DB\n+                        bug = Bug.get(idx)\n+\n+                    bugs.append(bug)\n+\n             elif topic.endswith('update.request.testing'):\n                 bugs = update.bugs\n             else:\n", "issue": "bodhi.server.consumers.updates.UpdatesHandler.consumer uses an assert statement\n```assert``` statements get removed from optimized code, which is what gets built in Koji (which is where production Bodhi builds come from). Thus, the assertion will not be present in production.\r\n\r\nIf the assertion is important, we should either reconcile the database discrepancy, or raise an Exception. It might make the most sense to reconcile the database discrepancy.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2015-2018 Red Hat Inc., and others.\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 along with\n# this program; if not, write to the Free Software Foundation, Inc., 51\n# Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n\"\"\"\nThe \"updates handler\".\n\nThis module is responsible for doing value-added work \"offline\" that used to be\ndone when updates were submitted.  Specifically, when someone submits an update\nwe used to:\n\n- Update any bugs in bugzilla associated with the update.\n- Check for test cases in the wiki.\n\nThose things could sometimes take a *very* long time, especially if there were\nlots of builds and lots of bugs in the update.\n\nNow, update-submission breezes by those steps and simply tells the user \"OK\".\nA fedmsg message gets published when their update goes through, and *that*\nmessage gets received here and triggers us to do all that network-laden heavy\nlifting.\n\"\"\"\n\nimport logging\nimport pprint\nimport time\n\nimport fedmsg.consumers\n\nfrom bodhi.server import initialize_db, util, bugs as bug_module\nfrom bodhi.server.config import config\nfrom bodhi.server.exceptions import BodhiException\nfrom bodhi.server.models import Bug, Update, UpdateType\n\n\nlog = logging.getLogger('bodhi')\n\n\nclass UpdatesHandler(fedmsg.consumers.FedmsgConsumer):\n    \"\"\"\n    Perform background tasks when updates are created or edited.\n\n    This fedmsg listener waits for messages from the frontend about new or edited updates, and\n    performs background tasks such as modifying Bugzilla issues (and loading information from\n    Bugzilla so we can display it to the user) and looking up wiki test cases.\n\n    Attributes:\n        db_factory (bodhi.server.util.TransactionalSessionMaker): A context manager that yields a\n            database session.\n        handle_bugs (bool): If True, interact with Bugzilla. Else do not.\n        topic (list): A list of strings that indicate which fedmsg topics this consumer listens to.\n    \"\"\"\n\n    config_key = 'updates_handler'\n\n    def __init__(self, hub, *args, **kwargs):\n        \"\"\"\n        Initialize the UpdatesHandler, subscribing it to the appropriate topics.\n\n        Args:\n            hub (moksha.hub.hub.CentralMokshaHub): The hub this handler is consuming messages from.\n                It is used to look up the hub config.\n        \"\"\"\n        initialize_db(config)\n        self.db_factory = util.transactional_session_maker()\n\n        prefix = hub.config.get('topic_prefix')\n        env = hub.config.get('environment')\n        self.topic = [\n            prefix + '.' + env + '.bodhi.update.request.testing',\n            prefix + '.' + env + '.bodhi.update.edit',\n        ]\n\n        self.handle_bugs = bool(config.get('bodhi_email'))\n        if not self.handle_bugs:\n            log.warning(\"No bodhi_email defined; not fetching bug details\")\n        else:\n            bug_module.set_bugtracker()\n\n        super(UpdatesHandler, self).__init__(hub, *args, **kwargs)\n        log.info('Bodhi updates handler listening on:\\n'\n                 '%s' % pprint.pformat(self.topic))\n\n    def consume(self, message):\n        \"\"\"\n        Process the given message, updating relevant bugs and test cases.\n\n        Args:\n            message (munch.Munch): A fedmsg about a new or edited update.\n        \"\"\"\n        msg = message['body']['msg']\n        topic = message['topic']\n        alias = msg['update'].get('alias')\n\n        log.info(\"Updates Handler handling  %s, %s\" % (alias, topic))\n\n        # Go to sleep for a second to try and avoid a race condition\n        # https://github.com/fedora-infra/bodhi/issues/458\n        time.sleep(1)\n\n        if not alias:\n            log.error(\"Update Handler got update with no \"\n                      \"alias %s.\" % pprint.pformat(msg))\n            return\n\n        with self.db_factory() as session:\n            update = Update.get(alias)\n            if not update:\n                raise BodhiException(\"Couldn't find alias '%s' in DB\" % alias)\n\n            if topic.endswith('update.edit'):\n                bugs = [Bug.get(idx) for idx in msg['new_bugs']]\n                # Sanity check\n                for bug in bugs:\n                    assert bug in update.bugs\n            elif topic.endswith('update.request.testing'):\n                bugs = update.bugs\n            else:\n                raise NotImplementedError(\"Should never get here.\")\n\n            self.work_on_bugs(session, update, bugs)\n            self.fetch_test_cases(session, update)\n\n        if config['test_gating.required']:\n            with self.db_factory() as session:\n                update = Update.get(alias)\n                update.update_test_gating_status()\n\n        log.info(\"Updates Handler done with %s, %s\" % (alias, topic))\n\n    def fetch_test_cases(self, session, update):\n        \"\"\"\n        Query the wiki for test cases for each package on the given update.\n\n        Args:\n            session (sqlalchemy.orm.session.Session): A database session.\n            update (bodhi.server.models.Update): The update's builds are iterated upon to find test\n                cases for their associated Packages..\n        \"\"\"\n        for build in update.builds:\n            build.package.fetch_test_cases(session)\n\n    def work_on_bugs(self, session, update, bugs):\n        \"\"\"\n        Iterate the list of bugs, retrieving information from Bugzilla and modifying them.\n\n        Iterate the given list of bugs associated with the given update. For each bug, retrieve\n        details from Bugzilla, comment on the bug to let watchers know about the update, and mark\n        the bug as MODIFIED. If the bug is a security issue, mark the update as a security update.\n\n        If the bug is private, Bodhi can't retrieve any information, comment on it, or modify\n        it, so we just associate the bug id with the update and mark it to be private.\n\n        If handle_bugs is not True, return and do nothing.\n\n        Args:\n            session (sqlalchemy.orm.session.Session): A database session.\n            update (bodhi.server.models.Update): The update that the bugs are associated with.\n            bugs (list): A list of bodhi.server.models.Bug instances that we wish to act on.\n        \"\"\"\n        if not self.handle_bugs:\n            log.warning(\"Not configured to handle bugs\")\n            return\n\n        log.info(\"Got %i bugs to sync for %r\" % (len(bugs), update.alias))\n        for bug in bugs:\n            log.info(\"Getting RHBZ bug %r\" % bug.bug_id)\n            try:\n                rhbz_bug = bug_module.bugtracker.getbug(bug.bug_id)\n\n                log.info(\"Updating our details for %r\" % bug.bug_id)\n                bug.update_details(rhbz_bug)\n                if bug.private:\n                    # Bodhi can't retrieve any information so just continue with the next bug\n                    log.info(\"  Skipping bug %r because it is private\" % (bug.bug_id))\n                    continue\n                log.info(\"  Got title %r for %r\" % (bug.title, bug.bug_id))\n\n                # If you set the type of your update to 'enhancement' but you\n                # attach a security bug, we automatically change the type of your\n                # update to 'security'. We need to do this first, so we don't\n                # accidentally comment on stuff that we shouldn't.\n                if bug.security:\n                    log.info(\"Setting our UpdateType to security.\")\n                    update.type = UpdateType.security\n\n                log.info(\"Commenting on %r\" % bug.bug_id)\n                comment = config['initial_bug_msg'] % (\n                    update.title, update.release.long_name, update.abs_url())\n\n                log.info(\"Modifying %r\" % bug.bug_id)\n                bug.modified(update, comment)\n            except Exception:\n                log.warning('Error occurred during updating single bug', exc_info=True)\n", "path": "bodhi/server/consumers/updates.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2015-2018 Red Hat Inc., and others.\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 along with\n# this program; if not, write to the Free Software Foundation, Inc., 51\n# Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n\"\"\"\nThe \"updates handler\".\n\nThis module is responsible for doing value-added work \"offline\" that used to be\ndone when updates were submitted.  Specifically, when someone submits an update\nwe used to:\n\n- Update any bugs in bugzilla associated with the update.\n- Check for test cases in the wiki.\n\nThose things could sometimes take a *very* long time, especially if there were\nlots of builds and lots of bugs in the update.\n\nNow, update-submission breezes by those steps and simply tells the user \"OK\".\nA fedmsg message gets published when their update goes through, and *that*\nmessage gets received here and triggers us to do all that network-laden heavy\nlifting.\n\"\"\"\n\nimport logging\nimport pprint\nimport time\n\nimport fedmsg.consumers\n\nfrom bodhi.server import initialize_db, util, bugs as bug_module\nfrom bodhi.server.config import config\nfrom bodhi.server.exceptions import BodhiException\nfrom bodhi.server.models import Bug, Update, UpdateType\n\n\nlog = logging.getLogger('bodhi')\n\n\nclass UpdatesHandler(fedmsg.consumers.FedmsgConsumer):\n    \"\"\"\n    Perform background tasks when updates are created or edited.\n\n    This fedmsg listener waits for messages from the frontend about new or edited updates, and\n    performs background tasks such as modifying Bugzilla issues (and loading information from\n    Bugzilla so we can display it to the user) and looking up wiki test cases.\n\n    Attributes:\n        db_factory (bodhi.server.util.TransactionalSessionMaker): A context manager that yields a\n            database session.\n        handle_bugs (bool): If True, interact with Bugzilla. Else do not.\n        topic (list): A list of strings that indicate which fedmsg topics this consumer listens to.\n    \"\"\"\n\n    config_key = 'updates_handler'\n\n    def __init__(self, hub, *args, **kwargs):\n        \"\"\"\n        Initialize the UpdatesHandler, subscribing it to the appropriate topics.\n\n        Args:\n            hub (moksha.hub.hub.CentralMokshaHub): The hub this handler is consuming messages from.\n                It is used to look up the hub config.\n        \"\"\"\n        initialize_db(config)\n        self.db_factory = util.transactional_session_maker()\n\n        prefix = hub.config.get('topic_prefix')\n        env = hub.config.get('environment')\n        self.topic = [\n            prefix + '.' + env + '.bodhi.update.request.testing',\n            prefix + '.' + env + '.bodhi.update.edit',\n        ]\n\n        self.handle_bugs = bool(config.get('bodhi_email'))\n        if not self.handle_bugs:\n            log.warning(\"No bodhi_email defined; not fetching bug details\")\n        else:\n            bug_module.set_bugtracker()\n\n        super(UpdatesHandler, self).__init__(hub, *args, **kwargs)\n        log.info('Bodhi updates handler listening on:\\n'\n                 '%s' % pprint.pformat(self.topic))\n\n    def consume(self, message):\n        \"\"\"\n        Process the given message, updating relevant bugs and test cases.\n\n        Args:\n            message (munch.Munch): A fedmsg about a new or edited update.\n        \"\"\"\n        msg = message['body']['msg']\n        topic = message['topic']\n        alias = msg['update'].get('alias')\n\n        log.info(\"Updates Handler handling  %s, %s\" % (alias, topic))\n\n        # Go to sleep for a second to try and avoid a race condition\n        # https://github.com/fedora-infra/bodhi/issues/458\n        time.sleep(1)\n\n        if not alias:\n            log.error(\"Update Handler got update with no \"\n                      \"alias %s.\" % pprint.pformat(msg))\n            return\n\n        with self.db_factory() as session:\n            update = Update.get(alias)\n            if not update:\n                raise BodhiException(\"Couldn't find alias '%s' in DB\" % alias)\n\n            bugs = []\n            if topic.endswith('update.edit'):\n                for idx in msg['new_bugs']:\n                    bug = Bug.get(idx)\n\n                    # Sanity check\n                    if bug is None or bug not in update.bugs:\n                        update_bugs_ids = [b.bug_id for b in update.bugs]\n                        update.update_bugs(update_bugs_ids + [idx], session)\n\n                        # Now, after update.update_bugs, bug with idx should exists in DB\n                        bug = Bug.get(idx)\n\n                    bugs.append(bug)\n\n            elif topic.endswith('update.request.testing'):\n                bugs = update.bugs\n            else:\n                raise NotImplementedError(\"Should never get here.\")\n\n            self.work_on_bugs(session, update, bugs)\n            self.fetch_test_cases(session, update)\n\n        if config['test_gating.required']:\n            with self.db_factory() as session:\n                update = Update.get(alias)\n                update.update_test_gating_status()\n\n        log.info(\"Updates Handler done with %s, %s\" % (alias, topic))\n\n    def fetch_test_cases(self, session, update):\n        \"\"\"\n        Query the wiki for test cases for each package on the given update.\n\n        Args:\n            session (sqlalchemy.orm.session.Session): A database session.\n            update (bodhi.server.models.Update): The update's builds are iterated upon to find test\n                cases for their associated Packages..\n        \"\"\"\n        for build in update.builds:\n            build.package.fetch_test_cases(session)\n\n    def work_on_bugs(self, session, update, bugs):\n        \"\"\"\n        Iterate the list of bugs, retrieving information from Bugzilla and modifying them.\n\n        Iterate the given list of bugs associated with the given update. For each bug, retrieve\n        details from Bugzilla, comment on the bug to let watchers know about the update, and mark\n        the bug as MODIFIED. If the bug is a security issue, mark the update as a security update.\n\n        If the bug is private, Bodhi can't retrieve any information, comment on it, or modify\n        it, so we just associate the bug id with the update and mark it to be private.\n\n        If handle_bugs is not True, return and do nothing.\n\n        Args:\n            session (sqlalchemy.orm.session.Session): A database session.\n            update (bodhi.server.models.Update): The update that the bugs are associated with.\n            bugs (list): A list of bodhi.server.models.Bug instances that we wish to act on.\n        \"\"\"\n        if not self.handle_bugs:\n            log.warning(\"Not configured to handle bugs\")\n            return\n\n        log.info(\"Got %i bugs to sync for %r\" % (len(bugs), update.alias))\n        for bug in bugs:\n            log.info(\"Getting RHBZ bug %r\" % bug.bug_id)\n            try:\n                rhbz_bug = bug_module.bugtracker.getbug(bug.bug_id)\n\n                log.info(\"Updating our details for %r\" % bug.bug_id)\n                bug.update_details(rhbz_bug)\n                if bug.private:\n                    # Bodhi can't retrieve any information so just continue with the next bug\n                    log.info(\"  Skipping bug %r because it is private\" % (bug.bug_id))\n                    continue\n                log.info(\"  Got title %r for %r\" % (bug.title, bug.bug_id))\n\n                # If you set the type of your update to 'enhancement' but you\n                # attach a security bug, we automatically change the type of your\n                # update to 'security'. We need to do this first, so we don't\n                # accidentally comment on stuff that we shouldn't.\n                if bug.security:\n                    log.info(\"Setting our UpdateType to security.\")\n                    update.type = UpdateType.security\n\n                log.info(\"Commenting on %r\" % bug.bug_id)\n                comment = config['initial_bug_msg'] % (\n                    update.title, update.release.long_name, update.abs_url())\n\n                log.info(\"Modifying %r\" % bug.bug_id)\n                bug.modified(update, comment)\n            except Exception:\n                log.warning('Error occurred during updating single bug', exc_info=True)\n", "path": "bodhi/server/consumers/updates.py"}]}