Skip to content

Commit

Permalink
Add dict to exception raised when encoding metadata fails
Browse files Browse the repository at this point in the history
Add the second part in the following traceback:

```
DEBUG    galaxy.metadata:__init__.py:93 setting metadata externally failed for HistoryDatasetAssociation 1: Traceback (most recent call last):
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/metadata.py", line 246, in to_JSON_dict
    encoded_meta_dict = galaxy.model.custom_types.json_encoder.encode(meta_dict)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/custom_types.py", line 39, in default
    return json.JSONEncoder.default(self, obj)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/metadata/set_metadata.py", line 334, in set_metadata_portable
    dataset.metadata.to_JSON_dict(filename_out)  # write out results of set_meta
  File "/usr/users/ga002/soranzon/software/nsoranzo_galaxy/lib/galaxy/model/metadata.py", line 248, in to_JSON_dict
    raise Exception(f"Failed encoding metadata dictionary: {meta_dict}") from e
Exception: Failed encoding metadata dictionary: {'dbkey': '?', 'title': None, 'description': None, 'url': None, 'doi': None, 'loom_spec_version': array([b'2.0.1'], dtype='|S6'), 'shape': (5, 10), 'layers
_count': 0, 'layers_names': [], 'row_attrs_count': 1, 'row_attrs_names': ['rownames'], 'col_attrs_count': 2, 'col_attrs_names': ['colnames', 'colnames_factor'], 'col_graphs_count': 0, 'col_graphs_names':
 [], 'row_graphs_count': 0, 'row_graphs_names': []}
```
  • Loading branch information
nsoranzo committed Sep 7, 2021
1 parent 2915310 commit 5cc7051
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/galaxy/model/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ def to_JSON_dict(self, filename=None):
meta_dict['__validated_state__'] = dataset_meta_dict['__validated_state__']
if '__validated_state_message__' in dataset_meta_dict:
meta_dict['__validated_state_message__'] = dataset_meta_dict['__validated_state_message__']
encoded_meta_dict = galaxy.model.custom_types.json_encoder.encode(meta_dict)
try:
encoded_meta_dict = galaxy.model.custom_types.json_encoder.encode(meta_dict)
except Exception as e:
raise Exception(f"Failed encoding metadata dictionary: {meta_dict}") from e
if filename is None:
return encoded_meta_dict
with open(filename, 'wt+') as fh:
Expand Down

0 comments on commit 5cc7051

Please sign in to comment.