We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Sometimes automatic updates miss changelog
For unknown reason, sometimes Koji is reporting empty rpm headers, so the automatic updates are missing the changelog and bugs aren't attached.

This seems the same cause of https://github.com/fedora-infra/bodhi/issues/4146

I've opened a ticket to Koji to try to find the root cause https://pagure.io/koji/issue/3178

--- 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/automatic_updates.py`
Content:
```
1 # Copyright © 2019 Red Hat, Inc. and others.
2 #
3 # This file is part of Bodhi.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 """
19 The Bodhi handler that creates updates automatically from tagged builds.
20 
21 This module is responsible for the process of creating updates when builds are
22 tagged with certain tags.
23 """
24 
25 import logging
26 import re
27 
28 import fedora_messaging
29 
30 from bodhi.server import buildsys
31 from bodhi.server.config import config
32 from bodhi.server.models import (
33     Bug, Build, ContentType, Package, Release, Update, UpdateStatus, UpdateType, User)
34 from bodhi.server.tasks import work_on_bugs_task
35 from bodhi.server.util import transactional_session_maker
36 
37 log = logging.getLogger('bodhi')
38 
39 
40 class AutomaticUpdateHandler:
41     """
42     The Bodhi Automatic Update Handler.
43 
44     A consumer that listens for messages about tagged builds and creates
45     updates from them.
46     """
47 
48     def __init__(self, db_factory: transactional_session_maker = None):
49         """
50         Initialize the Automatic Update Handler.
51 
52         Args:
53             db_factory: If given, used as the db_factory for this handler. If
54             None (the default), a new TransactionalSessionMaker is created and
55             used.
56         """
57         if not db_factory:
58             self.db_factory = transactional_session_maker()
59         else:
60             self.db_factory = db_factory
61 
62     def __call__(self, message: fedora_messaging.api.Message) -> None:
63         """Create updates from appropriately tagged builds.
64 
65         Args:
66             message: The message we are processing.
67         """
68         body = message.body
69 
70         missing = []
71         for mandatory in ('tag', 'build_id', 'name', 'version', 'release'):
72             if mandatory not in body:
73                 missing.append(mandatory)
74         if missing:
75             log.debug(f"Received incomplete tag message. Missing: {', '.join(missing)}")
76             return
77 
78         btag = body['tag']
79         bnvr = '{name}-{version}-{release}'.format(**body)
80 
81         koji = buildsys.get_session()
82 
83         kbuildinfo = koji.getBuild(bnvr)
84         if not kbuildinfo:
85             log.debug(f"Can't find Koji build for {bnvr}.")
86             return
87 
88         if 'nvr' not in kbuildinfo:
89             log.debug(f"Koji build info for {bnvr} doesn't contain 'nvr'.")
90             return
91 
92         if 'owner_name' not in kbuildinfo:
93             log.debug(f"Koji build info for {bnvr} doesn't contain 'owner_name'.")
94             return
95 
96         if kbuildinfo['owner_name'] in config.get('automatic_updates_blacklist'):
97             log.debug(f"{bnvr} owned by {kbuildinfo['owner_name']} who is listed in "
98                       "automatic_updates_blacklist, skipping.")
99             return
100 
101         # some APIs want the Koji build info, some others want the same
102         # wrapped in a larger (request?) structure
103         rbuildinfo = {
104             'info': kbuildinfo,
105             'nvr': kbuildinfo['nvr'].rsplit('-', 2),
106         }
107 
108         with self.db_factory() as dbsession:
109             rel = dbsession.query(Release).filter_by(create_automatic_updates=True,
110                                                      candidate_tag=btag).first()
111             if not rel:
112                 log.debug(f"Ignoring build being tagged into {btag!r}, no release configured for "
113                           "automatic updates for it found.")
114                 return
115 
116             bcls = ContentType.infer_content_class(Build, kbuildinfo)
117             build = bcls.get(bnvr)
118             if build and build.update:
119                 log.info(f"Build, active update for {bnvr} exists already, skipping.")
120                 return
121 
122             utype = (
123                 UpdateType.unspecified if Package.check_existence(rbuildinfo)
124                 else UpdateType.newpackage
125             )
126 
127             if not build:
128                 log.debug(f"Build for {bnvr} doesn't exist yet, creating.")
129 
130                 # Package.get_or_create() infers content type already
131                 log.debug("Getting/creating related package object.")
132                 pkg = Package.get_or_create(dbsession, rbuildinfo)
133 
134                 log.debug("Creating build object, adding it to the DB.")
135                 build = bcls(nvr=bnvr, package=pkg, release=rel)
136                 dbsession.add(build)
137 
138             owner_name = kbuildinfo['owner_name']
139             user = User.get(owner_name)
140             if not user:
141                 log.debug(f"Creating bodhi user for '{owner_name}'.")
142                 # Leave email, groups blank, these will be filled
143                 # in or updated when they log into Bodhi next time, see
144                 # bodhi.server.security:remember_me().
145                 user = User(name=owner_name)
146                 dbsession.add(user)
147 
148             log.debug(f"Creating new update for {bnvr}.")
149             try:
150                 changelog = build.get_changelog(lastupdate=True)
151             except ValueError:
152                 # Often due to bot-generated builds
153                 # https://github.com/fedora-infra/bodhi/issues/4146
154                 changelog = None
155             except Exception:
156                 # Re-raise exception, so that the message can be re-queued
157                 raise
158             closing_bugs = []
159             if changelog:
160                 log.debug("Adding changelog to update notes.")
161                 notes = f"""Automatic update for {bnvr}.
162 
163 ##### **Changelog**
164 
165 ```
166 {changelog}
167 ```"""
168 
169                 if rel.name not in config.get('bz_exclude_rels'):
170                     for b in re.finditer(config.get('bz_regex'), changelog, re.IGNORECASE):
171                         idx = int(b.group(1))
172                         log.debug(f'Adding bug #{idx} to the update.')
173                         bug = Bug.get(idx)
174                         if bug is None:
175                             bug = Bug(bug_id=idx)
176                             dbsession.add(bug)
177                             dbsession.flush()
178                         if bug not in closing_bugs:
179                             closing_bugs.append(bug)
180             else:
181                 notes = f"Automatic update for {bnvr}."
182             update = Update(
183                 release=rel,
184                 builds=[build],
185                 bugs=closing_bugs,
186                 notes=notes,
187                 type=utype,
188                 stable_karma=3,
189                 unstable_karma=-3,
190                 autokarma=False,
191                 user=user,
192                 status=UpdateStatus.pending,
193                 critpath=Update.contains_critpath_component([build], rel.branch),
194             )
195 
196             # Comment on the update that it was automatically created.
197             update.comment(
198                 dbsession,
199                 str("This update was automatically created"),
200                 author="bodhi",
201             )
202 
203             update.add_tag(update.release.pending_signing_tag)
204 
205             log.debug("Adding new update to the database.")
206             dbsession.add(update)
207 
208             log.debug("Flushing changes to the database.")
209             dbsession.flush()
210 
211             # Obsolete older updates which may be stuck in testing due to failed gating
212             try:
213                 update.obsolete_older_updates(dbsession)
214             except Exception as e:
215                 log.error(f'Problem obsoleting older updates: {e}')
216 
217             alias = update.alias
218             buglist = [b.bug_id for b in update.bugs]
219 
220         # This must be run after dbsession is closed so changes are committed to db
221         work_on_bugs_task.delay(alias, buglist)
222
```
--- 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/automatic_updates.py b/bodhi/server/consumers/automatic_updates.py
--- a/bodhi/server/consumers/automatic_updates.py
+++ b/bodhi/server/consumers/automatic_updates.py
@@ -22,6 +22,7 @@
 tagged with certain tags.
 """
 
+from time import sleep
 import logging
 import re
 
@@ -148,10 +149,13 @@
             log.debug(f"Creating new update for {bnvr}.")
             try:
                 changelog = build.get_changelog(lastupdate=True)
-            except ValueError:
+            except ValueError as e:
                 # Often due to bot-generated builds
-                # https://github.com/fedora-infra/bodhi/issues/4146
-                changelog = None
+                # https://pagure.io/koji/issue/3178
+                log.warning(str(e))
+                sleep(5)
+                # Re-raise exception, so that the message can be re-queued
+                raise
             except Exception:
                 # Re-raise exception, so that the message can be re-queued
                 raise

{"golden_diff": "diff --git a/bodhi/server/consumers/automatic_updates.py b/bodhi/server/consumers/automatic_updates.py\n--- a/bodhi/server/consumers/automatic_updates.py\n+++ b/bodhi/server/consumers/automatic_updates.py\n@@ -22,6 +22,7 @@\n tagged with certain tags.\n \"\"\"\n \n+from time import sleep\n import logging\n import re\n \n@@ -148,10 +149,13 @@\n             log.debug(f\"Creating new update for {bnvr}.\")\n             try:\n                 changelog = build.get_changelog(lastupdate=True)\n-            except ValueError:\n+            except ValueError as e:\n                 # Often due to bot-generated builds\n-                # https://github.com/fedora-infra/bodhi/issues/4146\n-                changelog = None\n+                # https://pagure.io/koji/issue/3178\n+                log.warning(str(e))\n+                sleep(5)\n+                # Re-raise exception, so that the message can be re-queued\n+                raise\n             except Exception:\n                 # Re-raise exception, so that the message can be re-queued\n                 raise\n", "issue": "Sometimes automatic updates miss changelog\nFor unknown reason, sometimes Koji is reporting empty rpm headers, so the automatic updates are missing the changelog and bugs aren't attached.\r\n\r\nThis seems the same cause of https://github.com/fedora-infra/bodhi/issues/4146\r\n\r\nI've opened a ticket to Koji to try to find the root cause https://pagure.io/koji/issue/3178\n", "before_files": [{"content": "# Copyright \u00a9 2019 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 Bodhi handler that creates updates automatically from tagged builds.\n\nThis module is responsible for the process of creating updates when builds are\ntagged with certain tags.\n\"\"\"\n\nimport logging\nimport re\n\nimport fedora_messaging\n\nfrom bodhi.server import buildsys\nfrom bodhi.server.config import config\nfrom bodhi.server.models import (\n    Bug, Build, ContentType, Package, Release, Update, UpdateStatus, UpdateType, User)\nfrom bodhi.server.tasks import work_on_bugs_task\nfrom bodhi.server.util import transactional_session_maker\n\nlog = logging.getLogger('bodhi')\n\n\nclass AutomaticUpdateHandler:\n    \"\"\"\n    The Bodhi Automatic Update Handler.\n\n    A consumer that listens for messages about tagged builds and creates\n    updates from them.\n    \"\"\"\n\n    def __init__(self, db_factory: transactional_session_maker = None):\n        \"\"\"\n        Initialize the Automatic Update Handler.\n\n        Args:\n            db_factory: If given, used as the db_factory for this handler. If\n            None (the default), a new TransactionalSessionMaker is created and\n            used.\n        \"\"\"\n        if not db_factory:\n            self.db_factory = transactional_session_maker()\n        else:\n            self.db_factory = db_factory\n\n    def __call__(self, message: fedora_messaging.api.Message) -> None:\n        \"\"\"Create updates from appropriately tagged builds.\n\n        Args:\n            message: The message we are processing.\n        \"\"\"\n        body = message.body\n\n        missing = []\n        for mandatory in ('tag', 'build_id', 'name', 'version', 'release'):\n            if mandatory not in body:\n                missing.append(mandatory)\n        if missing:\n            log.debug(f\"Received incomplete tag message. Missing: {', '.join(missing)}\")\n            return\n\n        btag = body['tag']\n        bnvr = '{name}-{version}-{release}'.format(**body)\n\n        koji = buildsys.get_session()\n\n        kbuildinfo = koji.getBuild(bnvr)\n        if not kbuildinfo:\n            log.debug(f\"Can't find Koji build for {bnvr}.\")\n            return\n\n        if 'nvr' not in kbuildinfo:\n            log.debug(f\"Koji build info for {bnvr} doesn't contain 'nvr'.\")\n            return\n\n        if 'owner_name' not in kbuildinfo:\n            log.debug(f\"Koji build info for {bnvr} doesn't contain 'owner_name'.\")\n            return\n\n        if kbuildinfo['owner_name'] in config.get('automatic_updates_blacklist'):\n            log.debug(f\"{bnvr} owned by {kbuildinfo['owner_name']} who is listed in \"\n                      \"automatic_updates_blacklist, skipping.\")\n            return\n\n        # some APIs want the Koji build info, some others want the same\n        # wrapped in a larger (request?) structure\n        rbuildinfo = {\n            'info': kbuildinfo,\n            'nvr': kbuildinfo['nvr'].rsplit('-', 2),\n        }\n\n        with self.db_factory() as dbsession:\n            rel = dbsession.query(Release).filter_by(create_automatic_updates=True,\n                                                     candidate_tag=btag).first()\n            if not rel:\n                log.debug(f\"Ignoring build being tagged into {btag!r}, no release configured for \"\n                          \"automatic updates for it found.\")\n                return\n\n            bcls = ContentType.infer_content_class(Build, kbuildinfo)\n            build = bcls.get(bnvr)\n            if build and build.update:\n                log.info(f\"Build, active update for {bnvr} exists already, skipping.\")\n                return\n\n            utype = (\n                UpdateType.unspecified if Package.check_existence(rbuildinfo)\n                else UpdateType.newpackage\n            )\n\n            if not build:\n                log.debug(f\"Build for {bnvr} doesn't exist yet, creating.\")\n\n                # Package.get_or_create() infers content type already\n                log.debug(\"Getting/creating related package object.\")\n                pkg = Package.get_or_create(dbsession, rbuildinfo)\n\n                log.debug(\"Creating build object, adding it to the DB.\")\n                build = bcls(nvr=bnvr, package=pkg, release=rel)\n                dbsession.add(build)\n\n            owner_name = kbuildinfo['owner_name']\n            user = User.get(owner_name)\n            if not user:\n                log.debug(f\"Creating bodhi user for '{owner_name}'.\")\n                # Leave email, groups blank, these will be filled\n                # in or updated when they log into Bodhi next time, see\n                # bodhi.server.security:remember_me().\n                user = User(name=owner_name)\n                dbsession.add(user)\n\n            log.debug(f\"Creating new update for {bnvr}.\")\n            try:\n                changelog = build.get_changelog(lastupdate=True)\n            except ValueError:\n                # Often due to bot-generated builds\n                # https://github.com/fedora-infra/bodhi/issues/4146\n                changelog = None\n            except Exception:\n                # Re-raise exception, so that the message can be re-queued\n                raise\n            closing_bugs = []\n            if changelog:\n                log.debug(\"Adding changelog to update notes.\")\n                notes = f\"\"\"Automatic update for {bnvr}.\n\n##### **Changelog**\n\n```\n{changelog}\n```\"\"\"\n\n                if rel.name not in config.get('bz_exclude_rels'):\n                    for b in re.finditer(config.get('bz_regex'), changelog, re.IGNORECASE):\n                        idx = int(b.group(1))\n                        log.debug(f'Adding bug #{idx} to the update.')\n                        bug = Bug.get(idx)\n                        if bug is None:\n                            bug = Bug(bug_id=idx)\n                            dbsession.add(bug)\n                            dbsession.flush()\n                        if bug not in closing_bugs:\n                            closing_bugs.append(bug)\n            else:\n                notes = f\"Automatic update for {bnvr}.\"\n            update = Update(\n                release=rel,\n                builds=[build],\n                bugs=closing_bugs,\n                notes=notes,\n                type=utype,\n                stable_karma=3,\n                unstable_karma=-3,\n                autokarma=False,\n                user=user,\n                status=UpdateStatus.pending,\n                critpath=Update.contains_critpath_component([build], rel.branch),\n            )\n\n            # Comment on the update that it was automatically created.\n            update.comment(\n                dbsession,\n                str(\"This update was automatically created\"),\n                author=\"bodhi\",\n            )\n\n            update.add_tag(update.release.pending_signing_tag)\n\n            log.debug(\"Adding new update to the database.\")\n            dbsession.add(update)\n\n            log.debug(\"Flushing changes to the database.\")\n            dbsession.flush()\n\n            # Obsolete older updates which may be stuck in testing due to failed gating\n            try:\n                update.obsolete_older_updates(dbsession)\n            except Exception as e:\n                log.error(f'Problem obsoleting older updates: {e}')\n\n            alias = update.alias\n            buglist = [b.bug_id for b in update.bugs]\n\n        # This must be run after dbsession is closed so changes are committed to db\n        work_on_bugs_task.delay(alias, buglist)\n", "path": "bodhi/server/consumers/automatic_updates.py"}], "after_files": [{"content": "# Copyright \u00a9 2019 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 Bodhi handler that creates updates automatically from tagged builds.\n\nThis module is responsible for the process of creating updates when builds are\ntagged with certain tags.\n\"\"\"\n\nfrom time import sleep\nimport logging\nimport re\n\nimport fedora_messaging\n\nfrom bodhi.server import buildsys\nfrom bodhi.server.config import config\nfrom bodhi.server.models import (\n    Bug, Build, ContentType, Package, Release, Update, UpdateStatus, UpdateType, User)\nfrom bodhi.server.tasks import work_on_bugs_task\nfrom bodhi.server.util import transactional_session_maker\n\nlog = logging.getLogger('bodhi')\n\n\nclass AutomaticUpdateHandler:\n    \"\"\"\n    The Bodhi Automatic Update Handler.\n\n    A consumer that listens for messages about tagged builds and creates\n    updates from them.\n    \"\"\"\n\n    def __init__(self, db_factory: transactional_session_maker = None):\n        \"\"\"\n        Initialize the Automatic Update Handler.\n\n        Args:\n            db_factory: If given, used as the db_factory for this handler. If\n            None (the default), a new TransactionalSessionMaker is created and\n            used.\n        \"\"\"\n        if not db_factory:\n            self.db_factory = transactional_session_maker()\n        else:\n            self.db_factory = db_factory\n\n    def __call__(self, message: fedora_messaging.api.Message) -> None:\n        \"\"\"Create updates from appropriately tagged builds.\n\n        Args:\n            message: The message we are processing.\n        \"\"\"\n        body = message.body\n\n        missing = []\n        for mandatory in ('tag', 'build_id', 'name', 'version', 'release'):\n            if mandatory not in body:\n                missing.append(mandatory)\n        if missing:\n            log.debug(f\"Received incomplete tag message. Missing: {', '.join(missing)}\")\n            return\n\n        btag = body['tag']\n        bnvr = '{name}-{version}-{release}'.format(**body)\n\n        koji = buildsys.get_session()\n\n        kbuildinfo = koji.getBuild(bnvr)\n        if not kbuildinfo:\n            log.debug(f\"Can't find Koji build for {bnvr}.\")\n            return\n\n        if 'nvr' not in kbuildinfo:\n            log.debug(f\"Koji build info for {bnvr} doesn't contain 'nvr'.\")\n            return\n\n        if 'owner_name' not in kbuildinfo:\n            log.debug(f\"Koji build info for {bnvr} doesn't contain 'owner_name'.\")\n            return\n\n        if kbuildinfo['owner_name'] in config.get('automatic_updates_blacklist'):\n            log.debug(f\"{bnvr} owned by {kbuildinfo['owner_name']} who is listed in \"\n                      \"automatic_updates_blacklist, skipping.\")\n            return\n\n        # some APIs want the Koji build info, some others want the same\n        # wrapped in a larger (request?) structure\n        rbuildinfo = {\n            'info': kbuildinfo,\n            'nvr': kbuildinfo['nvr'].rsplit('-', 2),\n        }\n\n        with self.db_factory() as dbsession:\n            rel = dbsession.query(Release).filter_by(create_automatic_updates=True,\n                                                     candidate_tag=btag).first()\n            if not rel:\n                log.debug(f\"Ignoring build being tagged into {btag!r}, no release configured for \"\n                          \"automatic updates for it found.\")\n                return\n\n            bcls = ContentType.infer_content_class(Build, kbuildinfo)\n            build = bcls.get(bnvr)\n            if build and build.update:\n                log.info(f\"Build, active update for {bnvr} exists already, skipping.\")\n                return\n\n            utype = (\n                UpdateType.unspecified if Package.check_existence(rbuildinfo)\n                else UpdateType.newpackage\n            )\n\n            if not build:\n                log.debug(f\"Build for {bnvr} doesn't exist yet, creating.\")\n\n                # Package.get_or_create() infers content type already\n                log.debug(\"Getting/creating related package object.\")\n                pkg = Package.get_or_create(dbsession, rbuildinfo)\n\n                log.debug(\"Creating build object, adding it to the DB.\")\n                build = bcls(nvr=bnvr, package=pkg, release=rel)\n                dbsession.add(build)\n\n            owner_name = kbuildinfo['owner_name']\n            user = User.get(owner_name)\n            if not user:\n                log.debug(f\"Creating bodhi user for '{owner_name}'.\")\n                # Leave email, groups blank, these will be filled\n                # in or updated when they log into Bodhi next time, see\n                # bodhi.server.security:remember_me().\n                user = User(name=owner_name)\n                dbsession.add(user)\n\n            log.debug(f\"Creating new update for {bnvr}.\")\n            try:\n                changelog = build.get_changelog(lastupdate=True)\n            except ValueError as e:\n                # Often due to bot-generated builds\n                # https://pagure.io/koji/issue/3178\n                log.warning(str(e))\n                sleep(5)\n                # Re-raise exception, so that the message can be re-queued\n                raise\n            except Exception:\n                # Re-raise exception, so that the message can be re-queued\n                raise\n            closing_bugs = []\n            if changelog:\n                log.debug(\"Adding changelog to update notes.\")\n                notes = f\"\"\"Automatic update for {bnvr}.\n\n##### **Changelog**\n\n```\n{changelog}\n```\"\"\"\n\n                if rel.name not in config.get('bz_exclude_rels'):\n                    for b in re.finditer(config.get('bz_regex'), changelog, re.IGNORECASE):\n                        idx = int(b.group(1))\n                        log.debug(f'Adding bug #{idx} to the update.')\n                        bug = Bug.get(idx)\n                        if bug is None:\n                            bug = Bug(bug_id=idx)\n                            dbsession.add(bug)\n                            dbsession.flush()\n                        if bug not in closing_bugs:\n                            closing_bugs.append(bug)\n            else:\n                notes = f\"Automatic update for {bnvr}.\"\n            update = Update(\n                release=rel,\n                builds=[build],\n                bugs=closing_bugs,\n                notes=notes,\n                type=utype,\n                stable_karma=3,\n                unstable_karma=-3,\n                autokarma=False,\n                user=user,\n                status=UpdateStatus.pending,\n                critpath=Update.contains_critpath_component([build], rel.branch),\n            )\n\n            # Comment on the update that it was automatically created.\n            update.comment(\n                dbsession,\n                str(\"This update was automatically created\"),\n                author=\"bodhi\",\n            )\n\n            update.add_tag(update.release.pending_signing_tag)\n\n            log.debug(\"Adding new update to the database.\")\n            dbsession.add(update)\n\n            log.debug(\"Flushing changes to the database.\")\n            dbsession.flush()\n\n            # Obsolete older updates which may be stuck in testing due to failed gating\n            try:\n                update.obsolete_older_updates(dbsession)\n            except Exception as e:\n                log.error(f'Problem obsoleting older updates: {e}')\n\n            alias = update.alias\n            buglist = [b.bug_id for b in update.bugs]\n\n        # This must be run after dbsession is closed so changes are committed to db\n        work_on_bugs_task.delay(alias, buglist)\n", "path": "bodhi/server/consumers/automatic_updates.py"}]}