From 3e4089526e7d5f1c04dceb0418bcc58c681e64fd Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 15 Nov 2023 14:12:07 -0500 Subject: [PATCH] Fix duplicated tools in tool panel view section copying. --- lib/galaxy/tool_util/toolbox/panel.py | 28 ++++++++++++++++++-- lib/galaxy/tool_util/toolbox/views/static.py | 5 ++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tool_util/toolbox/panel.py b/lib/galaxy/tool_util/toolbox/panel.py index 8375d39441d..0c98a28d3f2 100644 --- a/lib/galaxy/tool_util/toolbox/panel.py +++ b/lib/galaxy/tool_util/toolbox/panel.py @@ -63,14 +63,38 @@ class ToolSection(Dictifiable, HasPanelItems): self.links = item.get("links") or None self.elems = ToolPanelElements() - def copy(self): + def copy(self, merge_tools=False): copy = ToolSection() copy.name = self.name copy.id = self.id copy.version = self.version copy.description = self.description copy.links = self.links - copy.elems.update(self.elems) + + for key, panel_type, value in self.panel_items_iter(): + if panel_type == panel_item_types.TOOL and merge_tools: + tool = value + tool_lineage = tool.lineage + + tool_copied = False + if tool_lineage is not None: + version_ids = tool_lineage.get_version_ids(reverse=True) + + for version_id in version_ids: + if copy.elems.has_tool_with_id(version_id): + tool_copied = True + break + + if self.elems.has_tool_with_id(version_id): + copy.elems.append_tool(self.elems.get_tool_with_id(version_id)) + tool_copied = True + break + + if not tool_copied: + copy.elems[key] = value + else: + copy.elems[key] = value + return copy def to_dict(self, trans, link_details=False, tool_help=False, toolbox=None): diff --git a/lib/galaxy/tool_util/toolbox/views/static.py b/lib/galaxy/tool_util/toolbox/views/static.py index 750426e8908..2eba8eef3f4 100644 --- a/lib/galaxy/tool_util/toolbox/views/static.py +++ b/lib/galaxy/tool_util/toolbox/views/static.py @@ -120,7 +120,7 @@ class StaticToolPanelView(ToolPanelView): f"Failed to find matching section for (id, name) = ({element.section}, {element.section})" ) continue - section = closest_section.copy() + section = closest_section.copy(merge_tools=True) apply_filter(element, section.elems) new_panel.append_section(section.id, section) elif element.content_type == "label": @@ -151,7 +151,8 @@ class StaticToolPanelView(ToolPanelView): if closest_section is None: log.warning(f"Failed to find matching section for (id, name) = ({element.items_from}, None)") continue - elems = closest_section.elems.copy() + section = closest_section.copy(merge_tools=True) + elems = section.elems apply_filter(element, elems) for key, item in elems.items(): new_panel[key] = item