Merge pull request #18529 from mvdbeek/fix_get_edit_message_exception

Fix MessageException handling in get_edit
This commit is contained in:
Marius van den Beek
2024-07-17 17:04:12 +02:00
committed by GitHub
@@ -19,7 +19,10 @@ from galaxy.datatypes.display_applications.util import (
encode_dataset_user,
)
from galaxy.datatypes.sniff import guess_ext
from galaxy.exceptions import RequestParameterInvalidException
from galaxy.exceptions import (
MessageException,
RequestParameterInvalidException,
)
from galaxy.managers.hdas import (
HDADeserializer,
HDAManager,
@@ -158,7 +161,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
trans.response.headers.update(headers)
return display_data
@web.legacy_expose_api_anonymous
@web.expose_api_anonymous
def get_edit(self, trans, dataset_id=None, **kwd):
"""Produces the input definitions available to modify dataset attributes"""
status = None
@@ -168,8 +171,8 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
if self._can_access_dataset(trans, data):
if data.state == trans.model.Dataset.states.UPLOAD:
return self.message_exception(
trans, "Please wait until this dataset finishes uploading before attempting to edit its metadata."
raise MessageException(
"Please wait until this dataset finishes uploading before attempting to edit its metadata."
)
# let's not overwrite the imported datatypes module with the variable datatypes?
# the built-in 'id' is overwritten in lots of places as well
@@ -331,8 +334,8 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
"permission_disable": permission_disable,
}
else:
return self.message_exception(
trans, f"You do not have permission to edit this dataset's ( id: {dataset_id} ) information."
raise MessageException(
"You do not have permission to edit this dataset's ( id: {dataset_id} ) information."
)
@web.expose_api_anonymous
@@ -378,9 +381,8 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
if data.datatype.is_datatype_change_allowed():
# prevent modifying datatype when dataset is queued or running as input/output
if not data.ok_to_edit_metadata():
return self.message_exception(
trans,
"This dataset is currently being used as input or output. You cannot change datatype until the jobs have completed or you have canceled them.",
raise MessageException(
"This dataset is currently being used as input or output. You cannot change datatype until the jobs have completed or you have canceled them."
)
else:
path = data.dataset.get_file_name()
@@ -397,7 +399,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
trans.app.job_manager.enqueue(job, tool=trans.app.datatypes_registry.set_external_metadata_tool)
message = f"Detection was finished and changed the datatype to {datatype}."
else:
return self.message_exception(trans, f'Changing datatype "{data.extension}" is not allowed.')
raise MessageException(f'Changing datatype "{data.extension}" is not allowed.')
elif operation == "autodetect":
# The user clicked the Auto-detect button on the 'Edit Attributes' form
self.hda_manager.set_metadata(trans, data, overwrite=True)
@@ -408,7 +410,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
try:
message = data.datatype.convert_dataset(trans, data, target_type)
except DatatypeConverterNotFoundException as e:
return self.message_exception(trans, str(e))
raise MessageException(str(e))
elif operation == "permission":
# Adapt form request to API - style.
payload_permissions = {}
@@ -425,7 +427,7 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE
)
message = "Your changes completed successfully."
else:
return self.message_exception(trans, f"Invalid operation identifier ({operation}).")
raise MessageException(f"Invalid operation identifier ({operation}).")
return {"status": status, "message": sanitize_text(message)}
def _get_dataset_for_edit(self, trans, dataset_id):