Skip to content

Commit

Permalink
Merge pull request #17937 from mvdbeek/fix_peek_display
Browse files Browse the repository at this point in the history
[24.0] Never fail dataset serialization if display_peek fails
  • Loading branch information
mvdbeek authored Apr 8, 2024
2 parents 89ac780 + 456f33f commit dda6133
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/galaxy/datatypes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:

def display_peek(self, dataset: DatasetProtocol) -> str:
"""Create HTML table, used for displaying peek"""
if not dataset.peek:
return "Peek not available"
out = ['<table cellspacing="0" cellpadding="3">']
try:
if not dataset.peek:
dataset.set_peek()
data = dataset.peek
lines = data.splitlines()
for line in lines:
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/datatypes/qiime2.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def set_peek(self, dataset: DatasetProtocol, **kwd) -> None:
dataset.peek = "\n".join(map(": ".join, self._peek(dataset)))

def display_peek(self, dataset: DatasetProtocol) -> str:
if dataset.metadata.semantic_type is None:
# Proxy for metadata elements not (yet) set
return "Peek unavailable"

def make_row(pair):
return f"<tr><th>{pair[0]}</th><td>{html.escape(pair[1])}</td></tr>"

Expand Down
6 changes: 5 additions & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4666,7 +4666,11 @@ def as_display_type(self, type, **kwd):
return self.datatype.as_display_type(self, type, **kwd)

def display_peek(self):
return self.datatype.display_peek(self)
try:
return self.datatype.display_peek(self)
except Exception:
log.exception("Error occurred while generating dataset peek")
return None

def display_name(self):
return self.datatype.display_name(self)
Expand Down
3 changes: 3 additions & 0 deletions test/unit/data/datatypes/test_qiime2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def test_qza_set_peek():
with get_input_files("qiime2.qza") as input_files:
dataset = MockDataset(1)
dataset.set_file_name(input_files[0])
dataset.metadata.semantic_type = None
dataset.metadata.uuid = None
assert qza.display_peek(dataset) == "Peek unavailable"

qza.set_meta(dataset)
qza.set_peek(dataset)
Expand Down

0 comments on commit dda6133

Please sign in to comment.