anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: virtool/virtool
Issue: Missing fields in edit reference request

The following fields are present in the get reference response, but missing for the edit reference request response:
`description`, `groups`, `restrict_source_types`, `source_types`

Changed files:
virtool/api/references.py, tests/api/test_references.py

diff --git a/tests/api/test_references.py b/tests/api/test_references.py
index adee0e5aa..136df7e58 100644
--- a/tests/api/test_references.py
+++ b/tests/api/test_references.py
@@ -329,8 +329,7 @@ async def test_edit(control_exists, control_id, mocker, spawn_client, check_ref_
         },
         {
             "$set": update
-        },
-        projection=virtool.db.references.PROJECTION
+        }
     )
 
     m_get_computed.assert_called_with(
diff --git a/virtool/api/references.py b/virtool/api/references.py
index c6694ef32..aebda01d7 100644
--- a/virtool/api/references.py
+++ b/virtool/api/references.py
@@ -505,7 +505,7 @@ async def edit(req):
 
     document = await db.references.find_one_and_update({"_id": ref_id}, {
         "$set": data
-    }, projection=virtool.db.references.PROJECTION)
+    })
 
     document = virtool.utils.base_processor(document)
Repository: virtool/virtool
Issue: Missing field in update subtraction request

GET subtraction request returns the subtraction details, including the `linked_samples` array:
```
data: {
  count: 7,
  file: {id: "17qp283m-ATgenomeTAIR9.171", name: "ATgenomeTAIR9.171"},
  gc :{a: 0.319, t: 0.319, g: 0.18, c: 0.18, n: 0.002},
  id: "000",
  is_host: true,
  job: {id: "8n83tngx"},
  linked_samples: [{…}, {…}],
  nickname: "edited7",
  ready: true,
  user: {id: "naomis"}
}
```

UPDATE subtraction request returns the subtraction details without the array:
```
data: {
  count: 7,
  file: {id:  "17qp283m-ATgenomeTAIR9.171", name:  "ATgenomeTAIR9.171"},
  gc: {a: 0.319, t: 0.319, g: 0.18, c: 0.18, n: 0.002},
  id: "000",
  is_host: true,
  job: {id: "8n83tngx"},
  nickname: "CHANGED",
  ready: true,
  user: {id: "naomis"}
}
```

Changed files:
virtool/api/subtractions.py

diff --git a/virtool/api/subtractions.py b/virtool/api/subtractions.py
index ec7a6dfdc..80c6543e9 100644
--- a/virtool/api/subtractions.py
+++ b/virtool/api/subtractions.py
@@ -156,6 +156,8 @@ async def edit(req):
     if document is None:
         return not_found()
 
+    document["linked_samples"] = await virtool.db.subtractions.get_linked_samples(db, subtraction_id)
+
     return json_response(virtool.utils.base_processor(document))
Repository: virtool/virtool
Issue: 500 on subtraction deletion

From #812:
> deleting subtraction seems to result in server error

Changed files:
virtool/api/subtractions.py

diff --git a/virtool/api/subtractions.py b/virtool/api/subtractions.py
index d7ef56ffe..d6c173ff0 100644
--- a/virtool/api/subtractions.py
+++ b/virtool/api/subtractions.py
@@ -162,6 +162,7 @@ async def edit(req):
 @routes.delete("/api/subtractions/{subtraction_id}", permission="modify_subtraction")
 async def remove(req):
     db = req.app["db"]
+    settings = req.app["settings"]
 
     subtraction_id = req.match_info["subtraction_id"]
 
@@ -173,7 +174,7 @@ async def remove(req):
     if delete_result.deleted_count == 0:
         return not_found()
 
-    index_path = virtool.subtractions.calculate_index_path(req["settings"], subtraction_id)
+    index_path = virtool.subtractions.calculate_index_path(settings, subtraction_id)
 
     await req.loop.run_in_executor(None, shutil.rmtree, index_path, True)
Repository: virtool/virtool
Issue: Sample Analyses deletion

Currently clicking the remove icon on an analysis listing for a sample removes it from the UI and sends the appropriate DELETE request, but on page reload/navigation it seems the analysis is not actually deleted on the server. 

Changed files:
virtool/api/analyses.py

diff --git a/virtool/api/analyses.py b/virtool/api/analyses.py
index f65ce63ff..8608ff679 100644
--- a/virtool/api/analyses.py
+++ b/virtool/api/analyses.py
@@ -68,6 +68,8 @@ async def remove(req):
     if not document["ready"]:
         return conflict("Analysis is still running")
 
+    await db.analyses.delete_one({"_id": analysis_id})
+
     return no_content()
Repository: virtool/virtool
Issue: Cannot determine algorithm type for format_analysis

The `pathoscope_bowtie` value for analysis `algorithm` field is tripping up `format_analysis()`.

Changed files:
virtool/otus.py, virtool/db/references.py, virtool/db/analyses.py, virtool/setup.py

diff --git a/virtool/db/analyses.py b/virtool/db/analyses.py
index 43e9cde70..fa147652c 100644
--- a/virtool/db/analyses.py
+++ b/virtool/db/analyses.py
@@ -43,7 +43,7 @@ async def format_analysis(db, settings, document):
     if algorithm == "nuvs":
         return await format_nuvs(db, settings, document)
 
-    if algorithm == "pathoscope":
+    if algorithm and "pathoscope" in algorithm:
         return await format_pathoscope(db, document)
 
     raise ValueError("Could not determine analysis algorithm")
diff --git a/virtool/db/references.py b/virtool/db/references.py
index b2499da53..92f97b6e4 100644
--- a/virtool/db/references.py
+++ b/virtool/db/references.py
@@ -391,8 +391,6 @@ async def get_latest_build(db, ref_id):
         "ready": True
     }, projection=["created_at", "version", "user"], sort=[("version", pymongo.DESCENDING)])
 
-    print(latest_build)
-
     if latest_build is None:
         return None
 
diff --git a/virtool/otus.py b/virtool/otus.py
index 7c115fbb4..f9a0e2a30 100644
--- a/virtool/otus.py
+++ b/virtool/otus.py
@@ -174,8 +174,6 @@ def format_otu(joined, issues=False, most_recent_change=None):
     if issues is False:
         issues = verify(joined)
 
-    print("ISSUES")
-
     formatted["issues"] = issues
 
     return formatted
diff --git a/virtool/setup.py b/virtool/setup.py
index 312a12b88..1f6a9fee6 100644
--- a/virtool/setup.py
+++ b/virtool/setup.py
@@ -223,8 +223,6 @@ async def setup_user(req):
 
     data = v.document
 
-    print(data)
-
     req.app["setup"].update({
         "first_user_id": data["user_id"],
         "first_user_password": virtool.users.hash_password(data["password"])
Repository: virtool/virtool
Issue: Closed websocket handler

This error occurs, most likely when a websocket connection is not properly closed:
```python
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x2dd1f88>; the handler is closed
```

This may be causing the hanging job bugs that are occuring on the CPH instance.

Changed files:
virtool/app_dispatcher.py

diff --git a/virtool/app_dispatcher.py b/virtool/app_dispatcher.py
index 45c67a14e..2cfa9c9a1 100644
--- a/virtool/app_dispatcher.py
+++ b/virtool/app_dispatcher.py
@@ -4,10 +4,15 @@ from copy import deepcopy
 import virtool.handlers.utils
 
 
+async def default_writer(connection, message):
+    return await connection.send(message)
+
+
 class Connection:
 
     def __init__(self, ws, session):
         self._ws = ws
+        self.ping = self._ws.ping()
         self.user_id = session.user_id
         self.groups = session.groups
         self.permissions = session.permissions
@@ -15,9 +20,6 @@ class Connection:
     async def send(self, message):
         await self._ws.send_json(message, dumps=virtool.handlers.utils.dumps)
 
-    def ping(self):
-        return self._ws.ping()
-
     async def close(self):
         await self._ws.close()
 
@@ -75,7 +77,7 @@ class Dispatcher:
             pass
 
     async def dispatch(self, interface, operation, data, connections=None, conn_filter=None, conn_modifier=None,
-                       writer=None):
+                       writer=default_writer):
         """
         Dispatch a ``message`` with a conserved format to a selection of active ``connections``.
 
@@ -124,17 +126,20 @@ class Dispatcher:
             for connection in connections:
                 conn_modifier(connection)
 
-        if writer:
-            if not callable(writer):
-                raise TypeError("writer must be callable")
-
-            for connection in connections:
-                await writer(connection, deepcopy(message))
+        if writer and not callable(writer):
+            raise TypeError("writer must be callable")
 
-            return
+        connections_to_remove = list()
 
         for connection in connections:
-            await connection.send(message)
+            try:
+                await writer(connection, deepcopy(message))
+            except RuntimeError as err:
+                if "unable to perform operation on <TCPTransport closed=True" in str(err):
+                    connections_to_remove.append(connection)
+
+        for connection in connections_to_remove:
+            self.remove_connection(connection)
 
     async def close(self):
         self.alive = False
Repository: virtool/virtool
Issue: KeyError during reference edit API call

Currently any changes to the reference by the edit icon or reference-specific settings results in a `PATCH /api/refs/:refId 500 (Internal Server Error)`, but on page reload shows that changes have been successful 

Changed files:
virtool/api/references.py

diff --git a/virtool/api/references.py b/virtool/api/references.py
index a99f6d997..04668e750 100644
--- a/virtool/api/references.py
+++ b/virtool/api/references.py
@@ -395,7 +395,7 @@ async def edit(req):
 
     document = virtool.utils.base_processor(document)
 
-    document.update(await virtool.db.references.get_computed(db, document["_id"], internal_control_id))
+    document.update(await virtool.db.references.get_computed(db, ref_id, internal_control_id))
 
     return json_response(document)
Repository: virtool/virtool
Issue: Update virus sequences when schema segment is removed

Deleting segments that are associated with sequences should result in unassignment.

Changed files:
virtool/api/otus.py, virtool/db/otus.py

diff --git a/virtool/api/otus.py b/virtool/api/otus.py
index 5201465be..661a948c2 100644
--- a/virtool/api/otus.py
+++ b/virtool/api/otus.py
@@ -176,6 +176,8 @@ async def edit(req):
         }
     })
 
+    await virtool.db.otus.update_sequence_segments(db, old, document)
+
     new = await virtool.db.otus.join(db, otu_id, document)
 
     issues = await virtool.db.otus.update_verification(db, new)
diff --git a/virtool/db/otus.py b/virtool/db/otus.py
index 1d6dc6127..81d702222 100644
--- a/virtool/db/otus.py
+++ b/virtool/db/otus.py
@@ -312,3 +312,22 @@ async def update_last_indexed_version(db, id_list, version):
     })
 
     return result
+
+
+async def update_sequence_segments(db, old, new):
+    if old is None or new is None:
+        return
+
+    old_names = {s["name"] for s in old["schema"]}
+    new_names = {s["name"] for s in new["schema"]}
+
+    if old_names == new_names:
+        return
+
+    to_unset = list(old_names - new_names)
+
+    await db.sequences.update_many({"otu_id": old["_id"], "segment": {"$in": to_unset}}, {
+        "$unset": {
+            "segment": ""
+        }
+    })
Repository: secure-systems-lab/securesystemslib
Issue: remove python2 shebang in hash module

**Description of issue or feature request**:
securesystemslib/hash.py has a python2 shebang line, which is obsolete (Py2 support was dropped a while ago) and wrong (no need run the module by itself).

**Current behavior**:
https://github.com/secure-systems-lab/securesystemslib/blob/416dab215bdb0ae1f7d9b4c7ec9da8013100c069/securesystemslib/hash.py#L1

**Expected behavior**:
No shebang line. 

**Bonus task**:

Review eligibility of shebang lines in other modules too. 



Changed files:
securesystemslib/hash.py

diff --git a/securesystemslib/hash.py b/securesystemslib/hash.py
index 4ea04e1..3a3c2f4 100755
--- a/securesystemslib/hash.py
+++ b/securesystemslib/hash.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python2
 """
 <Program Name>
   hash.py