Fix MessageException handling in get_edit

Fixes
https://sentry.galaxyproject.org/share/issue/18f12e228c8d4cf0ac62001b5f5ad938/:
```
Message
Uncaught exception in exposed API method:
Stack Trace

Newest

Error: Odd-length string
  File "encodings/hex_codec.py", line 19, in hex_decode
    return (binascii.a2b_hex(input), len(input))
Error: decoding with 'hex' codec failed (Error: Odd-length string)
  File "galaxy/security/idencoding.py", line 94, in decode_id
    return int(unicodify(id_cipher.decrypt(codecs.decode(obj_id, "hex"))).lstrip("!"))
MalformedId: Wrong  id ( undefined ) specified, unable to decode.
  File "galaxy/web/framework/decorators.py", line 206, in decorator
    rval = func(self, trans, *args, **kwargs)
  File "galaxy/webapps/galaxy/controllers/dataset.py", line 165, in get_edit
    data, message = self._get_dataset_for_edit(trans, dataset_id)
  File "galaxy/webapps/galaxy/controllers/dataset.py", line 433, in _get_dataset_for_edit
    id = self.decode_id(dataset_id)
  File "galaxy/webapps/base/controller.py", line 114, in decode_id
    return managers_base.decode_id(self.app, id)
  File "galaxy/managers/base.py", line 156, in decode_id
    return decode_with_security(app.security, id, kind=kind)
  File "galaxy/managers/base.py", line 160, in decode_with_security
    return security.decode_id(str(id), kind=kind)
  File "galaxy/security/idencoding.py", line 100, in decode_id
    raise galaxy.exceptions.MalformedId(
```
This commit is contained in:
mvdbeek
2024-07-10 17:34:45 +02:00
parent b4af9b39e4
commit 33ca29a4f8
@@ -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):