Make metadata_file query parameter mandatory

It doesn't work without the parameter and results in
```
  File "/Users/mvandenb/src/galaxy/lib/galaxy/webapps/galaxy/api/datasets.py", line 264, in get_metadata_file
    metadata_file_path, headers = self.service.get_metadata_file(trans, history_content_id, metadata_file)
  File "/Users/mvandenb/src/galaxy/lib/galaxy/webapps/galaxy/services/datasets.py", line 448, in get_metadata_file
    file_ext = hda.metadata.spec.get(metadata_file).get("file_ext", metadata_file)
AttributeError: 'NoneType' object has no attribute 'get'
```
This commit is contained in:
mvdbeek
2022-02-10 15:58:16 +01:00
parent fcb68abe1f
commit ac17b66acf
2 changed files with 8 additions and 8 deletions
+5 -5
View File
@@ -256,12 +256,12 @@ class FastAPIDatasets:
trans=DependsOnTrans,
history_id: EncodedDatabaseIdField = HistoryIDPathParam,
history_content_id: EncodedDatabaseIdField = DatasetIDPathParam,
metadata_file: Optional[str] = Query(
default=None,
metadata_name: str = Query(
...,
description="The name of the metadata file to retrieve.",
),
):
metadata_file_path, headers = self.service.get_metadata_file(trans, history_content_id, metadata_file)
metadata_file_path, headers = self.service.get_metadata_file(trans, history_content_id, metadata_name)
return FileResponse(path=cast(str, metadata_file_path), headers=headers)
@router.get(
@@ -446,13 +446,13 @@ class DatasetsController(BaseGalaxyAPIController):
return self.service.get_content_as_text(trans, dataset_id)
@web.expose_api_raw_anonymous_and_sessionless
def get_metadata_file(self, trans, history_content_id, history_id, metadata_file=None, **kwd):
def get_metadata_file(self, trans, history_content_id, history_id, metadata_name, **kwd):
"""
GET /api/histories/{history_id}/contents/{history_content_id}/metadata_file
"""
# TODO: remove open_file parameter when deleting this legacy endpoint
metadata_file, headers = self.service.get_metadata_file(
trans, history_content_id, metadata_file, open_file=True
trans, history_content_id, metadata_name, open_file=True
)
trans.response.headers.update(headers)
return metadata_file
@@ -434,7 +434,7 @@ class DatasetsService(ServiceBase, UsesVisualizationMixin):
self,
trans: ProvidesHistoryContext,
history_content_id: EncodedDatabaseIdField,
metadata_file: Optional[str] = None,
metadata_name: str,
open_file: bool = False,
):
"""
@@ -445,12 +445,12 @@ class DatasetsService(ServiceBase, UsesVisualizationMixin):
"""
decoded_content_id = self.decode_id(history_content_id)
hda = self.hda_manager.get_accessible(decoded_content_id, trans.user)
file_ext = hda.metadata.spec.get(metadata_file).get("file_ext", metadata_file)
file_ext = hda.metadata.spec.get(metadata_name).get("file_ext", metadata_name)
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
file_path = hda.metadata.get(metadata_name).file_name
if open_file:
return open(file_path, "rb"), headers
return file_path, headers