Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve various error conditions around downloading metadata files #16706

Draft
wants to merge 2 commits into
base: release_23.1
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/galaxy/webapps/galaxy/services/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,16 @@ def extra_files(
Generate list of extra files.
"""
hda = self.hda_manager.get_accessible(history_content_id, trans.user)
extra_files_path = hda.extra_files_path
rval = []
for root, directories, files in safe_walk(extra_files_path):
for directory in directories:
rval.append(
{"class": "Directory", "path": os.path.relpath(os.path.join(root, directory), extra_files_path)}
)
for file in files:
rval.append({"class": "File", "path": os.path.relpath(os.path.join(root, file), extra_files_path)})
if not hda.is_pending and hda.extra_files_path_exists():
extra_files_path = hda.extra_files_path
for root, directories, files in safe_walk(extra_files_path):
for directory in directories:
rval.append(
{"class": "Directory", "path": os.path.relpath(os.path.join(root, directory), extra_files_path)}
)
for file in files:
rval.append({"class": "File", "path": os.path.relpath(os.path.join(root, file), extra_files_path)})

return rval

Expand Down Expand Up @@ -642,12 +643,21 @@ def get_metadata_file(
TODO: Remove the `open_file` parameter when removing the associated legacy endpoint.
"""
hda = self.hda_manager.get_accessible(history_content_id, trans.user)
file_ext = hda.metadata.spec.get(metadata_file).get("file_ext", metadata_file)
if hda.is_pending:
raise galaxy_exceptions.AcceptedRetryLater("dataset not in terminal state, retry later.", retry_after=60)
file_ext = hda.metadata.spec.get(metadata_file, {}).get("file_ext", metadata_file)
fname = "".join(c in util.FILENAME_VALID_CHARS and c or "_" for c in hda.name)[0:150]
headers = {}
headers["Content-Type"] = "application/octet-stream"
headers["Content-Disposition"] = f'attachment; filename="Galaxy{hda.hid}-[{fname}].{file_ext}"'
file_path = hda.metadata.get(metadata_file).file_name
metadata_file_instance = hda.metadata.get(metadata_file)
if not metadata_file_instance:
return galaxy_exceptions.RequestParameterInvalidException(
f"metadata file '{metadata_file}' not valid for dataset."
)
file_path = metadata_file_instance.file_name
if not os.path.exists(file_path):
return galaxy_exceptions.ObjectNotFound(f"metadata file '{metadata_file}' not found.")
if open_file:
return open(file_path, "rb"), headers
return file_path, headers
Expand Down