From f70d556fc68f8fa49f56394e4c301e4b4a25bc3d Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 3 May 2024 15:18:50 -0400 Subject: [PATCH 1/5] Raise exception if collection elements missing during download --- lib/galaxy/managers/hdcas.py | 3 +++ lib/galaxy/webapps/galaxy/api/history_contents.py | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/managers/hdcas.py b/lib/galaxy/managers/hdcas.py index ad5bcda58e8..59b1fc4a5d4 100644 --- a/lib/galaxy/managers/hdcas.py +++ b/lib/galaxy/managers/hdcas.py @@ -42,6 +42,9 @@ def stream_dataset_collection(dataset_collection_instance, upstream_mod_zip=Fals def write_dataset_collection(dataset_collection_instance, archive): names, hdas = get_hda_and_element_identifiers(dataset_collection_instance) for name, hda in zip(names, hdas): + if not hda: + # TODO should we raise galaxy.exceptions.InternalServerError or create a new exception type? + raise Exception("Attempt to write dataset collection with missing elements") if hda.state != hda.states.OK: continue for file_path, relpath in hda.datatype.to_archive(dataset=hda, name=name): diff --git a/lib/galaxy/webapps/galaxy/api/history_contents.py b/lib/galaxy/webapps/galaxy/api/history_contents.py index bfab8f0ef44..1bb1e21ade1 100644 --- a/lib/galaxy/webapps/galaxy/api/history_contents.py +++ b/lib/galaxy/webapps/galaxy/api/history_contents.py @@ -626,8 +626,7 @@ class FastAPIHistoryContents: """Download the content of a history dataset collection as a `zip` archive while maintaining approximate collection structure. """ - archive = self.service.get_dataset_collection_archive_for_download(trans, id) - return StreamingResponse(archive.response(), headers=archive.get_headers()) + return self._download_collection(trans, id) @router.get( "/api/dataset_collections/{id}/download", @@ -644,8 +643,7 @@ class FastAPIHistoryContents: """Download the content of a history dataset collection as a `zip` archive while maintaining approximate collection structure. """ - archive = self.service.get_dataset_collection_archive_for_download(trans, id) - return StreamingResponse(archive.response(), headers=archive.get_headers()) + return self._download_collection(trans, id) @router.post( "/api/histories/{history_id}/contents/dataset_collections/{id}/prepare_download", @@ -1033,3 +1031,7 @@ class FastAPIHistoryContents: ) rval = self.service.materialize(trans, materialize_request) return rval + + def _download_collection(self, trans, id): + archive = self.service.get_dataset_collection_archive_for_download(trans, id) + return StreamingResponse(archive.response(), headers=archive.get_headers()) From 48771a9f6addf065ef308bb1ca1f76fa2f415569 Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 6 May 2024 13:43:40 -0400 Subject: [PATCH 2/5] Raise appropriate error; check collection populated state --- lib/galaxy/managers/hdcas.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/managers/hdcas.py b/lib/galaxy/managers/hdcas.py index 59b1fc4a5d4..39756b300f4 100644 --- a/lib/galaxy/managers/hdcas.py +++ b/lib/galaxy/managers/hdcas.py @@ -9,6 +9,7 @@ import logging from typing import Dict from galaxy import model +from galaxy.exceptions import RequestParameterInvalidException from galaxy.managers import ( annotatable, base, @@ -40,11 +41,10 @@ def stream_dataset_collection(dataset_collection_instance, upstream_mod_zip=Fals def write_dataset_collection(dataset_collection_instance, archive): + if not dataset_collection_instance.populated_optimized(): + raise RequestParameterInvalidException("Attempt to write dataset collection that has not been populated yet") names, hdas = get_hda_and_element_identifiers(dataset_collection_instance) for name, hda in zip(names, hdas): - if not hda: - # TODO should we raise galaxy.exceptions.InternalServerError or create a new exception type? - raise Exception("Attempt to write dataset collection with missing elements") if hda.state != hda.states.OK: continue for file_path, relpath in hda.datatype.to_archive(dataset=hda, name=name): From 0045692760fc93a05e852e0e9a771f13ec1b66a6 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 9 May 2024 12:08:20 -0400 Subject: [PATCH 3/5] Access `populated_optimized` on DatasetCollection, not instance. Co-authored-by: Marius van den Beek --- lib/galaxy/managers/hdcas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/hdcas.py b/lib/galaxy/managers/hdcas.py index 39756b300f4..69e0d3dfdcd 100644 --- a/lib/galaxy/managers/hdcas.py +++ b/lib/galaxy/managers/hdcas.py @@ -41,7 +41,7 @@ def stream_dataset_collection(dataset_collection_instance, upstream_mod_zip=Fals def write_dataset_collection(dataset_collection_instance, archive): - if not dataset_collection_instance.populated_optimized(): + if not dataset_collection_instance.collection.populated_optimized(): raise RequestParameterInvalidException("Attempt to write dataset collection that has not been populated yet") names, hdas = get_hda_and_element_identifiers(dataset_collection_instance) for name, hda in zip(names, hdas): From 880f3efdca1540876bb58ea5847307e393f01917 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 9 May 2024 13:16:23 -0400 Subject: [PATCH 4/5] Fix bug (populated_optimized is property, not method) --- lib/galaxy/managers/hdcas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/hdcas.py b/lib/galaxy/managers/hdcas.py index 69e0d3dfdcd..42d44824515 100644 --- a/lib/galaxy/managers/hdcas.py +++ b/lib/galaxy/managers/hdcas.py @@ -41,7 +41,7 @@ def stream_dataset_collection(dataset_collection_instance, upstream_mod_zip=Fals def write_dataset_collection(dataset_collection_instance, archive): - if not dataset_collection_instance.collection.populated_optimized(): + if not dataset_collection_instance.collection.populated_optimized: raise RequestParameterInvalidException("Attempt to write dataset collection that has not been populated yet") names, hdas = get_hda_and_element_identifiers(dataset_collection_instance) for name, hda in zip(names, hdas): From f218a396a0b7f21778315e1d6f5c1aa5c78aae74 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 10 May 2024 16:08:44 -0400 Subject: [PATCH 5/5] Disable download link if collection not populated --- .../History/CurrentCollection/CollectionOperations.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/components/History/CurrentCollection/CollectionOperations.vue b/client/src/components/History/CurrentCollection/CollectionOperations.vue index 2843caddf80..c8c20b4bef5 100644 --- a/client/src/components/History/CurrentCollection/CollectionOperations.vue +++ b/client/src/components/History/CurrentCollection/CollectionOperations.vue @@ -18,6 +18,8 @@ const rerunUrl = computed(() => const showCollectionDetailsUrl = computed(() => props.dsc.job_source_type == "Job" ? `/jobs/${props.dsc.job_source_id}/view` : null ); +const disableDownload = props.dsc.populated_state !== "ok"; + function onDownload() { window.location.href = downloadUrl.value; } @@ -28,6 +30,7 @@ function onDownload() {