Skip to content

Commit

Permalink
Merge pull request galaxyproject#18529 from mvdbeek/fix_get_edit_mess…
Browse files Browse the repository at this point in the history
…age_exception

Fix MessageException handling in get_edit
  • Loading branch information
mvdbeek committed Jul 17, 2024
2 parents 6548044 + 33ca29a commit 68a591f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/galaxy/webapps/galaxy/controllers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
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,
Expand Down Expand Up @@ -158,7 +161,7 @@ def display(
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
Expand All @@ -168,8 +171,8 @@ def get_edit(self, trans, dataset_id=None, **kwd):

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
Expand Down Expand Up @@ -331,8 +334,8 @@ def get_edit(self, trans, dataset_id=None, **kwd):
"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
Expand Down Expand Up @@ -378,9 +381,8 @@ def set_edit(self, trans, payload=None, **kwd):
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()
Expand All @@ -397,7 +399,7 @@ def set_edit(self, trans, payload=None, **kwd):
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)
Expand All @@ -408,7 +410,7 @@ def set_edit(self, trans, payload=None, **kwd):
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 = {}
Expand All @@ -425,7 +427,7 @@ def set_edit(self, trans, payload=None, **kwd):
)
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):
Expand Down

0 comments on commit 68a591f

Please sign in to comment.