internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: fedora-infra/bodhi

Issue:
sqlalchemy.orm.exc.DetachedInstanceError exception in the composer task.
Since we have released Bodhi 5.2 we are getting a lot of sqlalchemy.orm.exc.DetachedInstanceError exception in the composer task leading to the compose failing and needing to be resumed.




Discussion:

Resolving patch:
diff --git a/bodhi/server/util.py b/bodhi/server/util.py
--- a/bodhi/server/util.py
+++ b/bodhi/server/util.py
@@ -874,16 +874,16 @@ def __call__(self):
         Exceptions or rolls back the transaction. In either case, it also will close and remove the
         Session.
         """
-        self.session = Session()
+        session = Session()
         try:
-            yield self.session
-            self.session.commit()
+            yield session
+            session.commit()
         except Exception as e:
             # It is possible for session.rollback() to raise Exceptions, so we will wrap it in an
             # Exception handler as well so we can log the rollback failure and still raise the
             # original Exception.
             try:
-                self.session.rollback()
+                session.rollback()
             except Exception:
                 log.exception('An Exception was raised while rolling back a transaction.')
             raise e
@@ -897,7 +897,6 @@ def _end_session(self):
         This has been split off the main __call__ method to make it easier to
         mock it out in unit tests.
         """
-        self.session.close()
         Session.remove()
 
 


Test patch:
diff --git a/bodhi/tests/server/test_util.py b/bodhi/tests/server/test_util.py
--- a/bodhi/tests/server/test_util.py
+++ b/bodhi/tests/server/test_util.py
@@ -1443,7 +1443,6 @@ def test___call___fail_rollback_failure(self, Session, log_exception):
             'An Exception was raised while rolling back a transaction.')
         assert Session.return_value.commit.call_count == 0
         Session.return_value.rollback.assert_called_once_with()
-        Session.return_value.close.assert_called_once_with()
         Session.remove.assert_called_once_with()
 
     @mock.patch('bodhi.server.util.log.exception')
@@ -1466,7 +1465,6 @@ def test___call___fail_rollback_success(self, Session, log_exception):
         assert log_exception.call_count == 0
         assert Session.return_value.commit.call_count == 0
         Session.return_value.rollback.assert_called_once_with()
-        Session.return_value.close.assert_called_once_with()
         Session.remove.assert_called_once_with()
 
     @mock.patch('bodhi.server.util.log.exception')
@@ -1486,7 +1484,6 @@ def test___call___success(self, Session, log_exception):
         assert log_exception.call_count == 0
         assert Session.return_value.rollback.call_count == 0
         Session.return_value.commit.assert_called_once_with()
-        Session.return_value.close.assert_called_once_with()
         Session.remove.assert_called_once_with()
Repository: fedora-infra/bodhi

Issue:
bodhi.server.models.Bug.url is inaccessible
The Bug model has a url database column, but the column cannot be accessed via the model because the model defines a [```url``` property](https://github.com/fedora-infra/bodhi/blob/3.0.0/bodhi/server/models.py#L2740-L2742) that overrides it.

We should ensure that this column really cannot be reached, and if so we should just drop it since it is unused.
Docs build failures with Sphinx 3
bodhi fails to build from source on Fedora with Sphinx 3 series.

Downstream bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1823739

Error:
Warning, treated as error:
/builddir/build/BUILD/bodhi-5.1.1/bodhi/server/models.py:docstring of bodhi.server.models.Bug.url:1:duplicate object description of bodhi.server.models.Bug.url, other instance in developer/docblocks/bodhi.server.models, use :noindex: for one of them
make: *** [Makefile:51: html] Error 2
make: Leaving directory '/builddir/build/BUILD/bodhi-5.1.1/docs'
error: Bad exit status from /var/tmp/rpm-tmp.A6849v (%build)

Sphinx 3 changelog: https://www.sphinx-doc.org/en/master/changes.html#release-3-0-0-released-apr-06-2020


Discussion:

Possibly related to #1995

I think we can just drop the `url` column, since `Bug.url` is provided via the url property. I don't see anything in the code that stores the url in db.

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -4377,8 +4377,6 @@ class Bug(Base):
         bug_id (int): The bug's id.
         title (str): The description of the bug.
         security (bool): True if the bug is marked as a security issue.
-        url (str): The URL for the bug. Inaccessible due to being overridden by the url
-            property (https://github.com/fedora-infra/bodhi/issues/1995).
         parent (bool): True if this is a parent tracker bug for release-specific bugs.
     """
 
@@ -4395,9 +4393,6 @@ class Bug(Base):
     # If we're dealing with a security bug
     security = Column(Boolean, default=False)
 
-    # Bug URL.  If None, then assume it's in Red Hat Bugzilla
-    url = Column('url', UnicodeText)
-
     # If this bug is a parent tracker bug for release-specific bugs
     parent = Column(Boolean, default=False)
 


Test patch:
Repository: fedora-infra/bodhi

Issue:
no clickable link for updates with no builds
If an update include no builds, `get_title` will return an empty string and there will be no clickable title in UI.


Discussion:

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2673,9 +2673,13 @@ def build_label(build):
                 title += " more"
 
                 return title
+            elif len(self.builds) == 0:
+                return self.alias
             else:
                 return " and ".join([build_label(build) for build in self.builds])
         else:
+            if len(self.builds) == 0:
+                return self.alias
             all_nvrs = [x.nvr for x in self.builds]
             nvrs = all_nvrs[:limit]
             builds = delim.join(sorted(nvrs)) + \


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -2993,8 +2993,8 @@ def test_list_updates_by_multiple_usernames(self):
         assert len(body['updates']) == 2
 
         assert body['updates'][0]['title'] == 'bodhi-2.0-1.fc17'
-        # This one has a blank title because it doesn't have any builds associated with it yet.
-        assert body['updates'][1]['title'] == ''
+        # This one uses alias because it doesn't have any builds associated with it yet.
+        assert body['updates'][1]['title'] == body['updates'][1]['alias']
         assert body['updates'][0]['user']['name'] == 'guest'
         assert body['updates'][1]['user']['name'] == 'aUser'
 
diff --git a/bodhi/tests/server/test_models.py b/bodhi/tests/server/test_models.py
--- a/bodhi/tests/server/test_models.py
+++ b/bodhi/tests/server/test_models.py
@@ -3185,6 +3185,19 @@ def test_get_title_display_name(self):
 
         assert update.get_title(beautify=True) == 'some human made title'
 
+    @pytest.mark.parametrize('beautify', (False, True))
+    def test_get_title_no_builds(self, beautify):
+        """If the update include no builds, return update alias."""
+        update = self.get_update()
+        update.builds = []
+        assert update.get_title(beautify=beautify) == update.alias
+
+        update.display_name = 'some human made title'
+        if beautify:
+            assert update.get_title(beautify=beautify) == 'some human made title'
+        else:
+            assert update.get_title(beautify=beautify) == update.alias
+
     def test_get_title_with_beautify(self):
         update = self.get_update()
         rpm_build = update.builds[0]
Repository: fedora-infra/bodhi

Issue:
Add the possibility to query updates by releases in graphql
We currently have a getUpdates query in graphql that let us query updates using certain attributes, we should add the possibility to give a release name and get all the updates from a release.

For example ```query {getUpdates(releaseName: "F33") {alias}}```

For this we will most likely need to use a join query in the graphlq resolve function (https://github.com/fedora-infra/bodhi/blob/develop/bodhi/server/services/graphql.py#L132) to exploit the relationship between Updates and release.

Some hints https://stackoverflow.com/questions/8561470/sqlalchemy-filtering-by-relationship-attribute


Discussion:

Resolving patch:
diff --git a/bodhi/server/services/graphql.py b/bodhi/server/services/graphql.py
--- a/bodhi/server/services/graphql.py
+++ b/bodhi/server/services/graphql.py
@@ -58,7 +58,7 @@ class Query(graphene.ObjectType):
         status=graphene.String(), request=graphene.String(),
         pushed=graphene.Boolean(), critpath=graphene.Boolean(),
         date_approved=graphene.String(), alias=graphene.String(),
-        user_id=graphene.Int())
+        user_id=graphene.Int(), release_name=graphene.String())
 
     def resolve_allReleases(self, info):
         """Answer Queries by fetching data from the Schema."""
@@ -131,6 +131,10 @@ def resolve_getUpdates(self, info, **args):
         if user_id is not None:
             query = query.filter(UpdateModel.user_id == user_id)
 
+        release_name = args.get("release_name")
+        if release_name is not None:
+            query = query.join(UpdateModel.release).filter(ReleaseModel.name == release_name)
+
         return query.all()
 
 


Test patch:
diff --git a/bodhi/tests/server/services/test_graphql.py b/bodhi/tests/server/services/test_graphql.py
--- a/bodhi/tests/server/services/test_graphql.py
+++ b/bodhi/tests/server/services/test_graphql.py
@@ -181,3 +181,14 @@ def test_getUpdates(self):
                 }]
             }
         }
+
+        executed = client.execute("""{  getUpdates(releaseName: "F22"){  request  }}""")
+        assert executed == {
+            'data': {
+                'getUpdates': [{
+                    'request': 'testing',
+                }, {
+                    'request': 'testing',
+                }]
+            }
+        }
Repository: fedora-infra/bodhi

Issue:
Bodhi doesn't correctly mark updates as critpath updates for Rawhide
Rawhide updates are never identified as critpath updates:
https://bodhi.fedoraproject.org/updates/FEDORA-2021-c8f0463820
https://bodhi.fedoraproject.org/updates/FEDORA-2021-d8b1203333

The problem is in the interface with PDC:
https://github.com/fedora-infra/bodhi/blob/d275cc2bb9e513dc10e2009262adc989e199dadf/bodhi/server/models.py#L2103
and
https://github.com/fedora-infra/bodhi/blob/d275cc2bb9e513dc10e2009262adc989e199dadf/bodhi/server/util.py#L959

We query PDC for "name=f34", but rawhide in PDC is always "name=master"...


Discussion:

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2095,19 +2095,19 @@ def comments_since_karma_reset(self):
         return comments_since_karma_reset
 
     @staticmethod
-    def contains_critpath_component(builds, release_name):
+    def contains_critpath_component(builds, release_branch):
         """
         Determine if there is a critpath component in the builds passed in.
 
         Args:
             builds (list): :class:`Builds <Build>` to be considered.
-            release_name (str): The name of the release, such as "f25".
+            release_branch (str): The name of the git branch associated to the release,
+                such as "f25" or "master".
         Returns:
             bool: ``True`` if the update contains a critical path package, ``False`` otherwise.
         Raises:
             RuntimeError: If the PDC did not give us a 200 code.
         """
-        relname = release_name.lower()
         components = defaultdict(list)
         # Get the mess down to a dict of ptype -> [pname]
         for build in builds:
@@ -2116,7 +2116,7 @@ def contains_critpath_component(builds, release_name):
             components[ptype].append(pname)
 
         for ptype in components:
-            if get_critpath_components(relname, ptype, frozenset(components[ptype])):
+            if get_critpath_components(release_branch, ptype, frozenset(components[ptype])):
                 return True
 
         return False
@@ -2312,7 +2312,7 @@ def new(cls, request, data):
         data['user'] = user
         caveats = []
         data['critpath'] = cls.contains_critpath_component(
-            data['builds'], data['release'].name)
+            data['builds'], data['release'].branch)
 
         # Be sure to not add an empty string as alternative title
         # and strip whitespaces from it
@@ -2464,7 +2464,7 @@ def edit(cls, request, data):
                     db.delete(b)
 
         data['critpath'] = cls.contains_critpath_component(
-            up.builds, up.release.name)
+            up.builds, up.release.branch)
 
         del(data['builds'])
 


Test patch:
Repository: fedora-infra/bodhi

Issue:
A staging Bodhi links to the production Bugzilla
When I want to create an update on a staging Bodhi, and I'm offered to fill out the `Bugs` form field, the form correctly queries the [partner-bugzilla](https://partner-bugzilla.redhat.com/), not the production one. I can see that the populated title is correctly retrieved from there.

However, when I actually create the update and go to the `Bugs` tab, the bug item links to the production bugzilla instead, not the partner one.


Discussion:
As an update, partner-bugzilla is no more, the instance now lives under https://bugzilla.stage.redhat.com

Resolving patch:
diff --git a/bodhi/server/util.py b/bodhi/server/util.py
--- a/bodhi/server/util.py
+++ b/bodhi/server/util.py
@@ -630,9 +630,8 @@ def bug_link(context, bug, short=False):
     Returns:
         str: The requested link.
     """
-    url = "https://bugzilla.redhat.com/show_bug.cgi?id=" + str(bug.bug_id)
-    display = "BZ#%i" % bug.bug_id
-    link = "<a target='_blank' href='%s' class='notblue'>%s</a>" % (url, display)
+    url = config.get('buglink') % str(bug.bug_id)
+    link = f"<a target='_blank' href='{url}' class='notblue'>BZ#{bug.bug_id}</a>"
     if not short:
         if bug.title:
             # We're good, but we do need to clean the bug title in case it contains malicious


Test patch:
Repository: fedora-infra/bodhi

Issue:
Changing only the bugs associated with an update caused a change in its request status
There was [an update](https://bodhi.fedoraproject.org/updates/FEDORA-2021-256d5ee9fe) that was in "pending -> stable" state - last status change message was "This update has been submitted for stable by bodhi." I edited the update and changed *only* the bugs it is associated with (I added one). I didn't change the builds in the update at all. After this edit, a new status change message appeared - "This update has been submitted for testing by adamwill." - and the status changed to "pending -> testing". The "push to stable" action is not available on the Actions menu.

This doesn't seem right. An update shouldn't change from queued-for-stable to queued-for-testing just because I edited the bug list.


Discussion:

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2448,6 +2448,8 @@ def edit(cls, request, data):
         buildinfo = request.buildinfo
         up = db.query(Update).filter_by(alias=data['edited']).first()
         del(data['edited'])
+        data.pop("request", None)
+        req = None
 
         caveats = []
         edited_builds = [build.nvr for build in up.builds]
@@ -2530,7 +2532,7 @@ def edit(cls, request, data):
 
         # Updates with new or removed builds always go back to testing
         if new_builds or removed_builds:
-            data['request'] = UpdateRequest.testing
+            req = UpdateRequest.testing
             # And, updates with new or removed builds always get their karma reset.
             # https://github.com/fedora-infra/bodhi/issues/511
             data['karma_critipath'] = 0
@@ -2558,7 +2560,6 @@ def edit(cls, request, data):
         new_bugs = up.update_bugs(data['bugs'], db)
         del(data['bugs'])
 
-        req = data.pop("request", None)
         if req is not None and not data.get("from_tag"):
             up.set_request(db, req, request.user.name)
 


Test patch:
Repository: fedora-infra/bodhi

Issue:
bodhi --version is broken
```
$ bodhi --version
Traceback (most recent call last):
  File "/usr/bin/bodhi", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1054, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 920, in make_context
    self.parse_args(ctx, args)
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1613, in parse_args
    rest = super().parse_args(ctx, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 1378, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 2360, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/core.py", line 2322, in process_value
    value = self.callback(ctx, self, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/click/decorators.py", line 441, in callback
    raise RuntimeError(
RuntimeError: 'bodhi' is not installed. Try passing 'package_name' instead.
```


Discussion:

Resolving patch:
diff --git a/bodhi-client/bodhi/client/cli.py b/bodhi-client/bodhi/client/cli.py
--- a/bodhi-client/bodhi/client/cli.py
+++ b/bodhi-client/bodhi/client/cli.py
@@ -317,7 +317,7 @@ def _save_override(url: str, staging: bool, edit: bool = False,
 
 
 @click.group(help="Command line tool for interacting with Bodhi.")
-@click.version_option(message='%(version)s')
+@click.version_option(message='%(version)s', package_name='bodhi_client')
 def cli():
     """Create the main CLI group."""
     pass  # pragma: no cover


Test patch:
Repository: fedora-infra/bodhi

Issue:
"cannot access local variable 'tags'" error when editing flatpak updates
When editing builds in a flatpak update, e.g. https://bodhi.fedoraproject.org/updates/FEDORA-FLATPAK-2023-38c6f050df/edit Bodhi seems to always show the following error and the update ends up in an "unpushed" state:

```
Builds : Unable to create update. cannot access local variable 'tags' where it is not associated with a value
```


Discussion:
FWIW, traceback is: 

```
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/bodhi/server/services/updates.py", line 574, in new_update
    result, _caveats = Update.edit(request, data)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/bodhi/server/models.py", line 2692, in edit
    for tag in tags:
               ^^^^
UnboundLocalError: cannot access local variable 'tags' where it is not associated with a value
```

Resolving patch:
diff --git a/bodhi-server/bodhi/server/models.py b/bodhi-server/bodhi/server/models.py
--- a/bodhi-server/bodhi/server/models.py
+++ b/bodhi-server/bodhi/server/models.py
@@ -2681,16 +2681,17 @@ def edit(cls, request, data):
                 # and release-candidate tag if builds are in side-tag
                 builds_to_tag = new_builds
 
+            tags = []
             if up.from_tag and not up.release.composed_by_bodhi:
-                tags = [up.release.get_pending_signing_side_tag(up.from_tag)]
+                tags.append(up.release.get_pending_signing_side_tag(up.from_tag))
             elif up.from_tag:
-                tags = [up.release.candidate_tag]
+                tags.append(up.release.candidate_tag)
                 if up.release.pending_signing_tag:
                     tags.append(up.release.pending_signing_tag)
             else:
                 # For normal updates the builds already have candidate_tag
                 if up.release.pending_signing_tag:
-                    tags = [up.release.pending_signing_tag]
+                    tags.append(up.release.pending_signing_tag)
 
             for tag in tags:
                 tag_update_builds_task.delay(tag=tag, builds=builds_to_tag)


Test patch:
Repository: fedora-infra/bodhi

Issue:
Allow filtering release by multiple states
In the webUI `frozen` releases are showed within the same table as `pending` releases.
Json output is more pedantic in its output and filtering for `?state=pending` doesn't include frozen. I think this is correct, but there might be needs for query results that include both states, so let's modify the `state` parameter to accept a comma separated list of values, so we can filter by `?state=pending,frozen`


Discussion:

Resolving patch:
diff --git a/bodhi-server/bodhi/server/schemas.py b/bodhi-server/bodhi/server/schemas.py
--- a/bodhi-server/bodhi/server/schemas.py
+++ b/bodhi-server/bodhi/server/schemas.py
@@ -81,6 +81,13 @@ class Releases(colander.SequenceSchema):
     release = colander.SchemaNode(colander.String())
 
 
+class ReleaseStates(colander.SequenceSchema):
+    """A SequenceSchema to validate a list of ReleaseState objects."""
+
+    release_state = colander.SchemaNode(colander.String(),
+                                        validator=colander.OneOf(list(ReleaseState.values())))
+
+
 class ReleaseIds(colander.SequenceSchema):
     """A SequenceSchema to validate a list of Release ID objects."""
 
@@ -341,10 +348,11 @@ class ListReleaseSchema(PaginatedSchema):
         preparer=[util.splitter],
     )
 
-    state = colander.SchemaNode(
-        colander.String(),
-        validator=colander.OneOf(list(ReleaseState.values())),
+    state = ReleaseStates(
+        colander.Sequence(accept_scalar=True),
+        location="querystring",
         missing=None,
+        preparer=[util.splitter],
     )
 
     exclude_archived = colander.SchemaNode(
diff --git a/bodhi-server/bodhi/server/services/releases.py b/bodhi-server/bodhi/server/services/releases.py
--- a/bodhi-server/bodhi/server/services/releases.py
+++ b/bodhi-server/bodhi/server/services/releases.py
@@ -328,7 +328,7 @@ def query_releases_json(request):
 
     state = data.get('state')
     if state is not None:
-        query = query.filter(Release.state == ReleaseState.from_string(state))
+        query = query.filter(or_(*[Release.state == ReleaseState.from_string(s) for s in state]))
 
     query = query.order_by(Release.name.asc())
 


Test patch:
diff --git a/bodhi-server/tests/services/test_releases.py b/bodhi-server/tests/services/test_releases.py
--- a/bodhi-server/tests/services/test_releases.py
+++ b/bodhi-server/tests/services/test_releases.py
@@ -251,6 +251,14 @@ def test_list_releases_by_pending_state(self):
         body = res.json_body
         assert len(body['releases']) == 0
 
+    def test_list_releases_by_multiple_states(self):
+        """ Test that we can filter releases using multiple states """
+        res = self.app.get('/releases/', {"state": ['current', 'disabled']})
+        body = res.json_body
+        assert len(body['releases']) == 2
+        assert body['releases'][0]['name'] == 'F17'
+        assert body['releases'][1]['name'] == 'F22'
+
     def test_list_releases_with_a_wrong_state(self):
         """ Test that we get a 400 error when we use an undefined state """
         res = self.app.get('/releases/', {"state": 'active'}, status=400)