Unverified Commit d36888ad authored by mvdbeek's avatar mvdbeek
Browse files

Fix contains_collection check for empty root collections

Comparing hdca_id with parent_id is just wrong, as hdca_id is the id for
a `HistoryDatasetCollectionAssociation`, while `parent_id` is the id for
a `DatasetCollection`. This happened to work regardless of the first if
check if the root collection contains at least one DCE, but that won't
work for collections without elements.
parent cba4677b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -5811,6 +5811,9 @@ class HistoryDatasetCollectionAssociation(
        """Checks to see that the indicated collection is a member of the
        hdca by using a recursive CTE sql query to find the collection's parents
        and checking to see if any of the parents are associated with this hdca"""
        if collection_id == self.collection_id:
            # collection_id is root collection
            return True

        sa_session = object_session(self)
        DCE = DatasetCollectionElement
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ class DatasetCollectionsService(ServiceBase, UsesLibraryMixinItems):

        # check to make sure the dsc is part of the validated hdca
        decoded_parent_id = self.decode_id(parent_id)
        if parent_id != hdca_id and not hdca.contains_collection(decoded_parent_id):
        if not hdca.contains_collection(decoded_parent_id):
            raise exceptions.ObjectNotFound('Requested dataset collection is not contained within indicated history content')

        # retrieve contents
+8 −0
Original line number Diff line number Diff line
@@ -358,6 +358,14 @@ class DatasetCollectionApiTestCase(ApiTestCase):
        assert len(offset_contents) == 1
        assert offset_contents[0]['element_index'] == 1

    def test_collection_contents_empty_root(self):
        hdca = self.dataset_collection_populator.create_list_in_history(self.history_id, contents=[]).json()
        assert hdca["elements"] == []
        root_contents_url = hdca["contents_url"]
        response = self._get(root_contents_url)
        response.raise_for_status()
        assert response.json() == []

    def test_get_suitable_converters_single_datatype(self):
        response = self.dataset_collection_populator.upload_collection(self.history_id, "list:paired", elements=[
            {