Unverified Commit 1d85f4fd authored by Björn Grüning's avatar Björn Grüning Committed by GitHub
Browse files

Merge pull request #14103 from mvdbeek/fix_contains_collection

[22.01] Fix contains_collection check for empty root collections
parents cba4677b d36888ad
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=[
            {