We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
add build completion to buildroot override add
From: https://fedorahosted.org/bodhi/ticket/788

"Small regression in Bodhi 2.0: builds completion fails to work in the override page.

I tried to submit an override for qpid-cpp-0.32-8.fc23 (due to boost rebuild induced ABI break), and it failed in both discovering the name of the source package and the nvr."


--- 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/views/generic.py`
Content:
```
1 # This program is free software; you can redistribute it and/or
2 # modify it under the terms of the GNU General Public License
3 # as published by the Free Software Foundation; either version 2
4 # of the License, or (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14 
15 import datetime
16 import sqlalchemy as sa
17 
18 from pyramid.security import authenticated_userid
19 from pyramid.view import view_config, notfound_view_config
20 from pyramid.exceptions import HTTPNotFound, HTTPForbidden
21 
22 from bodhi import log
23 import bodhi.models
24 import bodhi.util
25 
26 
27 @notfound_view_config(append_slash=True)
28 def notfound_view(context, request):
29     """ Automatically redirects to slash-appended routes.
30 
31     http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#redirecting-to-slash-appended-rou
32     """
33     return HTTPNotFound()
34 
35 
36 def get_top_testers(request):
37     db = request.db
38     blacklist = request.registry.settings.get('stats_blacklist').split()
39     days = int(request.registry.settings.get('top_testers_timeframe', 7))
40     start_time = datetime.datetime.utcnow() - datetime.timedelta(days=days)
41 
42     query = db.query(
43         bodhi.models.User,
44         sa.func.count(bodhi.models.User.comments).label('count_1')
45     ).join(bodhi.models.Comment)
46     query = query\
47         .order_by('count_1 desc')\
48         .filter(bodhi.models.Comment.timestamp > start_time)
49 
50     for user in blacklist:
51         query = query.filter(bodhi.models.User.name != user)
52 
53     return query\
54         .group_by(bodhi.models.User)\
55         .limit(5)\
56         .all()
57 
58 
59 def get_latest_updates(request, critpath, security):
60     db = request.db
61     query = db.query(bodhi.models.Update)
62 
63     if critpath:
64         query = query.filter(
65             bodhi.models.Update.critpath==True)
66     if security:
67         query = query.filter(
68             bodhi.models.Update.type==bodhi.models.UpdateType.security)
69 
70     query = query.filter(
71         bodhi.models.Update.status==bodhi.models.UpdateStatus.testing)
72 
73     query = query.order_by(bodhi.models.Update.date_submitted.desc())
74     return query.limit(5).all()
75 
76 
77 @view_config(route_name='home', renderer='home.html')
78 def home(request):
79     """ Returns data for the frontpage """
80     r = request
81 
82     @request.cache.cache_on_arguments()
83     def work():
84         top_testers = get_top_testers(request)
85         critpath_updates = get_latest_updates(request, True, False)
86         security_updates = get_latest_updates(request, False, True)
87 
88         return {
89             "top_testers": [(obj.__json__(r), n) for obj, n in top_testers],
90             "critpath_updates": [obj.__json__(r) for obj in critpath_updates],
91             "security_updates": [obj.__json__(r) for obj in security_updates],
92         }
93 
94     return work()
95 
96 
97 @view_config(route_name='new_update', renderer='new_update.html')
98 def new_update(request):
99     """ Returns the new update form """
100     user = authenticated_userid(request)
101     if not user:
102         raise HTTPForbidden("You must be logged in.")
103     return dict(
104         update=None,
105         types=reversed(bodhi.models.UpdateType.values()),
106         severities=reversed(bodhi.models.UpdateSeverity.values()),
107         suggestions=reversed(bodhi.models.UpdateSuggestion.values()),
108     )
109 
110 
111 @view_config(route_name='latest_candidates', renderer='json')
112 def latest_candidates(request):
113     """
114     For a given `package`, this method returns the most recent builds tagged
115     into the Release.candidate_tag for all Releases.
116     """
117     koji = request.koji
118     db = request.db
119 
120     @request.cache.cache_on_arguments()
121     def work(pkg):
122         result = []
123         koji.multicall = True
124 
125         releases = db.query(bodhi.models.Release) \
126                      .filter(
127                          bodhi.models.Release.state.in_(
128                              (bodhi.models.ReleaseState.pending,
129                               bodhi.models.ReleaseState.current)))
130 
131         for release in releases:
132             koji.listTagged(release.candidate_tag, package=pkg, latest=True)
133 
134         builds = koji.multiCall() or []  # Protect against None
135 
136         for build in builds:
137             if isinstance(build, dict):
138                 continue
139             if build and build[0] and build[0][0]:
140                 result.append({
141                     'nvr': build[0][0]['nvr'],
142                     'id': build[0][0]['id'],
143                 })
144         return result
145 
146 
147     pkg = request.params.get('package')
148     log.debug('latest_candidate(%r)' % pkg)
149 
150     if not pkg:
151         return []
152 
153     result = work(pkg)
154 
155     log.debug(result)
156     return result
157 
158 
159 @view_config(route_name='latest_builds', renderer='json')
160 def latest_builds(request):
161     """ Get a list of the latest builds for a given package.
162 
163     Returns a dictionary of the release dist tag to the latest build.
164     """
165     builds = {}
166     koji = request.koji
167     package = request.params.get('package')
168     for tag_type, tags in bodhi.models.Release.get_tags()[0].iteritems():
169         for tag in tags:
170             try:
171                 for build in koji.getLatestBuilds(tag, package=package):
172                     builds[tag] = build['nvr']
173             except:  # Things like EPEL don't have pending tags
174                 pass
175     return builds
176 
177 
178 @view_config(route_name='new_override', renderer='override.html')
179 def new_override(request):
180     """ Returns the new buildroot override form """
181     user = authenticated_userid(request)
182     if not user:
183         raise HTTPForbidden("You must be logged in.")
184     return dict()
185 
186 
187 @view_config(route_name='api_version', renderer='json')
188 def api_version(request):
189     """ Returns the Bodhi API version """
190     return dict(version=bodhi.util.version())
191
```
--- 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/views/generic.py b/bodhi/views/generic.py
--- a/bodhi/views/generic.py
+++ b/bodhi/views/generic.py
@@ -16,6 +16,7 @@
 import sqlalchemy as sa
 
 from pyramid.security import authenticated_userid
+from pyramid.settings import asbool
 from pyramid.view import view_config, notfound_view_config
 from pyramid.exceptions import HTTPNotFound, HTTPForbidden
 
@@ -118,7 +119,7 @@
     db = request.db
 
     @request.cache.cache_on_arguments()
-    def work(pkg):
+    def work(pkg, testing):
         result = []
         koji.multicall = True
 
@@ -128,8 +129,12 @@
                              (bodhi.models.ReleaseState.pending,
                               bodhi.models.ReleaseState.current)))
 
+        kwargs = dict(package=pkg, latest=True)
         for release in releases:
-            koji.listTagged(release.candidate_tag, package=pkg, latest=True)
+            koji.listTagged(release.candidate_tag, **kwargs)
+            if testing:
+                koji.listTagged(release.testing_tag, **kwargs)
+                koji.listTagged(release.pending_testing_tag, **kwargs)
 
         builds = koji.multiCall() or []  # Protect against None
 
@@ -145,12 +150,13 @@
 
 
     pkg = request.params.get('package')
-    log.debug('latest_candidate(%r)' % pkg)
+    testing = asbool(request.params.get('testing'))
+    log.debug('latest_candidate(%r, %r)' % (pkg, testing))
 
     if not pkg:
         return []
 
-    result = work(pkg)
+    result = work(pkg, testing)
 
     log.debug(result)
     return result

{"golden_diff": "diff --git a/bodhi/views/generic.py b/bodhi/views/generic.py\n--- a/bodhi/views/generic.py\n+++ b/bodhi/views/generic.py\n@@ -16,6 +16,7 @@\n import sqlalchemy as sa\n \n from pyramid.security import authenticated_userid\n+from pyramid.settings import asbool\n from pyramid.view import view_config, notfound_view_config\n from pyramid.exceptions import HTTPNotFound, HTTPForbidden\n \n@@ -118,7 +119,7 @@\n     db = request.db\n \n     @request.cache.cache_on_arguments()\n-    def work(pkg):\n+    def work(pkg, testing):\n         result = []\n         koji.multicall = True\n \n@@ -128,8 +129,12 @@\n                              (bodhi.models.ReleaseState.pending,\n                               bodhi.models.ReleaseState.current)))\n \n+        kwargs = dict(package=pkg, latest=True)\n         for release in releases:\n-            koji.listTagged(release.candidate_tag, package=pkg, latest=True)\n+            koji.listTagged(release.candidate_tag, **kwargs)\n+            if testing:\n+                koji.listTagged(release.testing_tag, **kwargs)\n+                koji.listTagged(release.pending_testing_tag, **kwargs)\n \n         builds = koji.multiCall() or []  # Protect against None\n \n@@ -145,12 +150,13 @@\n \n \n     pkg = request.params.get('package')\n-    log.debug('latest_candidate(%r)' % pkg)\n+    testing = asbool(request.params.get('testing'))\n+    log.debug('latest_candidate(%r, %r)' % (pkg, testing))\n \n     if not pkg:\n         return []\n \n-    result = work(pkg)\n+    result = work(pkg, testing)\n \n     log.debug(result)\n     return result\n", "issue": "add build completion to buildroot override add\nFrom: https://fedorahosted.org/bodhi/ticket/788\n\n\"Small regression in Bodhi 2.0: builds completion fails to work in the override page.\n\nI tried to submit an override for qpid-cpp-0.32-8.fc23 (due to boost rebuild induced ABI break), and it failed in both discovering the name of the source package and the nvr.\"\n\n", "before_files": [{"content": "# 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\nimport datetime\nimport sqlalchemy as sa\n\nfrom pyramid.security import authenticated_userid\nfrom pyramid.view import view_config, notfound_view_config\nfrom pyramid.exceptions import HTTPNotFound, HTTPForbidden\n\nfrom bodhi import log\nimport bodhi.models\nimport bodhi.util\n\n\n@notfound_view_config(append_slash=True)\ndef notfound_view(context, request):\n    \"\"\" Automatically redirects to slash-appended routes.\n\n    http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#redirecting-to-slash-appended-rou\n    \"\"\"\n    return HTTPNotFound()\n\n\ndef get_top_testers(request):\n    db = request.db\n    blacklist = request.registry.settings.get('stats_blacklist').split()\n    days = int(request.registry.settings.get('top_testers_timeframe', 7))\n    start_time = datetime.datetime.utcnow() - datetime.timedelta(days=days)\n\n    query = db.query(\n        bodhi.models.User,\n        sa.func.count(bodhi.models.User.comments).label('count_1')\n    ).join(bodhi.models.Comment)\n    query = query\\\n        .order_by('count_1 desc')\\\n        .filter(bodhi.models.Comment.timestamp > start_time)\n\n    for user in blacklist:\n        query = query.filter(bodhi.models.User.name != user)\n\n    return query\\\n        .group_by(bodhi.models.User)\\\n        .limit(5)\\\n        .all()\n\n\ndef get_latest_updates(request, critpath, security):\n    db = request.db\n    query = db.query(bodhi.models.Update)\n\n    if critpath:\n        query = query.filter(\n            bodhi.models.Update.critpath==True)\n    if security:\n        query = query.filter(\n            bodhi.models.Update.type==bodhi.models.UpdateType.security)\n\n    query = query.filter(\n        bodhi.models.Update.status==bodhi.models.UpdateStatus.testing)\n\n    query = query.order_by(bodhi.models.Update.date_submitted.desc())\n    return query.limit(5).all()\n\n\n@view_config(route_name='home', renderer='home.html')\ndef home(request):\n    \"\"\" Returns data for the frontpage \"\"\"\n    r = request\n\n    @request.cache.cache_on_arguments()\n    def work():\n        top_testers = get_top_testers(request)\n        critpath_updates = get_latest_updates(request, True, False)\n        security_updates = get_latest_updates(request, False, True)\n\n        return {\n            \"top_testers\": [(obj.__json__(r), n) for obj, n in top_testers],\n            \"critpath_updates\": [obj.__json__(r) for obj in critpath_updates],\n            \"security_updates\": [obj.__json__(r) for obj in security_updates],\n        }\n\n    return work()\n\n\n@view_config(route_name='new_update', renderer='new_update.html')\ndef new_update(request):\n    \"\"\" Returns the new update form \"\"\"\n    user = authenticated_userid(request)\n    if not user:\n        raise HTTPForbidden(\"You must be logged in.\")\n    return dict(\n        update=None,\n        types=reversed(bodhi.models.UpdateType.values()),\n        severities=reversed(bodhi.models.UpdateSeverity.values()),\n        suggestions=reversed(bodhi.models.UpdateSuggestion.values()),\n    )\n\n\n@view_config(route_name='latest_candidates', renderer='json')\ndef latest_candidates(request):\n    \"\"\"\n    For a given `package`, this method returns the most recent builds tagged\n    into the Release.candidate_tag for all Releases.\n    \"\"\"\n    koji = request.koji\n    db = request.db\n\n    @request.cache.cache_on_arguments()\n    def work(pkg):\n        result = []\n        koji.multicall = True\n\n        releases = db.query(bodhi.models.Release) \\\n                     .filter(\n                         bodhi.models.Release.state.in_(\n                             (bodhi.models.ReleaseState.pending,\n                              bodhi.models.ReleaseState.current)))\n\n        for release in releases:\n            koji.listTagged(release.candidate_tag, package=pkg, latest=True)\n\n        builds = koji.multiCall() or []  # Protect against None\n\n        for build in builds:\n            if isinstance(build, dict):\n                continue\n            if build and build[0] and build[0][0]:\n                result.append({\n                    'nvr': build[0][0]['nvr'],\n                    'id': build[0][0]['id'],\n                })\n        return result\n\n\n    pkg = request.params.get('package')\n    log.debug('latest_candidate(%r)' % pkg)\n\n    if not pkg:\n        return []\n\n    result = work(pkg)\n\n    log.debug(result)\n    return result\n\n\n@view_config(route_name='latest_builds', renderer='json')\ndef latest_builds(request):\n    \"\"\" Get a list of the latest builds for a given package.\n\n    Returns a dictionary of the release dist tag to the latest build.\n    \"\"\"\n    builds = {}\n    koji = request.koji\n    package = request.params.get('package')\n    for tag_type, tags in bodhi.models.Release.get_tags()[0].iteritems():\n        for tag in tags:\n            try:\n                for build in koji.getLatestBuilds(tag, package=package):\n                    builds[tag] = build['nvr']\n            except:  # Things like EPEL don't have pending tags\n                pass\n    return builds\n\n\n@view_config(route_name='new_override', renderer='override.html')\ndef new_override(request):\n    \"\"\" Returns the new buildroot override form \"\"\"\n    user = authenticated_userid(request)\n    if not user:\n        raise HTTPForbidden(\"You must be logged in.\")\n    return dict()\n\n\n@view_config(route_name='api_version', renderer='json')\ndef api_version(request):\n    \"\"\" Returns the Bodhi API version \"\"\"\n    return dict(version=bodhi.util.version())\n", "path": "bodhi/views/generic.py"}], "after_files": [{"content": "# 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\nimport datetime\nimport sqlalchemy as sa\n\nfrom pyramid.security import authenticated_userid\nfrom pyramid.settings import asbool\nfrom pyramid.view import view_config, notfound_view_config\nfrom pyramid.exceptions import HTTPNotFound, HTTPForbidden\n\nfrom bodhi import log\nimport bodhi.models\nimport bodhi.util\n\n\n@notfound_view_config(append_slash=True)\ndef notfound_view(context, request):\n    \"\"\" Automatically redirects to slash-appended routes.\n\n    http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#redirecting-to-slash-appended-rou\n    \"\"\"\n    return HTTPNotFound()\n\n\ndef get_top_testers(request):\n    db = request.db\n    blacklist = request.registry.settings.get('stats_blacklist').split()\n    days = int(request.registry.settings.get('top_testers_timeframe', 7))\n    start_time = datetime.datetime.utcnow() - datetime.timedelta(days=days)\n\n    query = db.query(\n        bodhi.models.User,\n        sa.func.count(bodhi.models.User.comments).label('count_1')\n    ).join(bodhi.models.Comment)\n    query = query\\\n        .order_by('count_1 desc')\\\n        .filter(bodhi.models.Comment.timestamp > start_time)\n\n    for user in blacklist:\n        query = query.filter(bodhi.models.User.name != user)\n\n    return query\\\n        .group_by(bodhi.models.User)\\\n        .limit(5)\\\n        .all()\n\n\ndef get_latest_updates(request, critpath, security):\n    db = request.db\n    query = db.query(bodhi.models.Update)\n\n    if critpath:\n        query = query.filter(\n            bodhi.models.Update.critpath==True)\n    if security:\n        query = query.filter(\n            bodhi.models.Update.type==bodhi.models.UpdateType.security)\n\n    query = query.filter(\n        bodhi.models.Update.status==bodhi.models.UpdateStatus.testing)\n\n    query = query.order_by(bodhi.models.Update.date_submitted.desc())\n    return query.limit(5).all()\n\n\n@view_config(route_name='home', renderer='home.html')\ndef home(request):\n    \"\"\" Returns data for the frontpage \"\"\"\n    r = request\n\n    @request.cache.cache_on_arguments()\n    def work():\n        top_testers = get_top_testers(request)\n        critpath_updates = get_latest_updates(request, True, False)\n        security_updates = get_latest_updates(request, False, True)\n\n        return {\n            \"top_testers\": [(obj.__json__(r), n) for obj, n in top_testers],\n            \"critpath_updates\": [obj.__json__(r) for obj in critpath_updates],\n            \"security_updates\": [obj.__json__(r) for obj in security_updates],\n        }\n\n    return work()\n\n\n@view_config(route_name='new_update', renderer='new_update.html')\ndef new_update(request):\n    \"\"\" Returns the new update form \"\"\"\n    user = authenticated_userid(request)\n    if not user:\n        raise HTTPForbidden(\"You must be logged in.\")\n    return dict(\n        update=None,\n        types=reversed(bodhi.models.UpdateType.values()),\n        severities=reversed(bodhi.models.UpdateSeverity.values()),\n        suggestions=reversed(bodhi.models.UpdateSuggestion.values()),\n    )\n\n\n@view_config(route_name='latest_candidates', renderer='json')\ndef latest_candidates(request):\n    \"\"\"\n    For a given `package`, this method returns the most recent builds tagged\n    into the Release.candidate_tag for all Releases.\n    \"\"\"\n    koji = request.koji\n    db = request.db\n\n    @request.cache.cache_on_arguments()\n    def work(pkg, testing):\n        result = []\n        koji.multicall = True\n\n        releases = db.query(bodhi.models.Release) \\\n                     .filter(\n                         bodhi.models.Release.state.in_(\n                             (bodhi.models.ReleaseState.pending,\n                              bodhi.models.ReleaseState.current)))\n\n        kwargs = dict(package=pkg, latest=True)\n        for release in releases:\n            koji.listTagged(release.candidate_tag, **kwargs)\n            if testing:\n                koji.listTagged(release.testing_tag, **kwargs)\n                koji.listTagged(release.pending_testing_tag, **kwargs)\n\n        builds = koji.multiCall() or []  # Protect against None\n\n        for build in builds:\n            if isinstance(build, dict):\n                continue\n            if build and build[0] and build[0][0]:\n                result.append({\n                    'nvr': build[0][0]['nvr'],\n                    'id': build[0][0]['id'],\n                })\n        return result\n\n\n    pkg = request.params.get('package')\n    testing = asbool(request.params.get('testing'))\n    log.debug('latest_candidate(%r, %r)' % (pkg, testing))\n\n    if not pkg:\n        return []\n\n    result = work(pkg, testing)\n\n    log.debug(result)\n    return result\n\n\n@view_config(route_name='latest_builds', renderer='json')\ndef latest_builds(request):\n    \"\"\" Get a list of the latest builds for a given package.\n\n    Returns a dictionary of the release dist tag to the latest build.\n    \"\"\"\n    builds = {}\n    koji = request.koji\n    package = request.params.get('package')\n    for tag_type, tags in bodhi.models.Release.get_tags()[0].iteritems():\n        for tag in tags:\n            try:\n                for build in koji.getLatestBuilds(tag, package=package):\n                    builds[tag] = build['nvr']\n            except:  # Things like EPEL don't have pending tags\n                pass\n    return builds\n\n\n@view_config(route_name='new_override', renderer='override.html')\ndef new_override(request):\n    \"\"\" Returns the new buildroot override form \"\"\"\n    user = authenticated_userid(request)\n    if not user:\n        raise HTTPForbidden(\"You must be logged in.\")\n    return dict()\n\n\n@view_config(route_name='api_version', renderer='json')\ndef api_version(request):\n    \"\"\" Returns the Bodhi API version \"\"\"\n    return dict(version=bodhi.util.version())\n", "path": "bodhi/views/generic.py"}]}