From 061d5a4b6258f7c5cfabd6b910f103af8f1d69f5 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:29:05 +0200 Subject: [PATCH 1/3] copy comments when copying workflow --- lib/galaxy/model/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 3e78689a2a39..9de5be22593a 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -7707,6 +7707,25 @@ def copy(self, user=None): for old_step, new_step in zip(self.steps, copied_steps): old_step.copy_to(new_step, step_mapping, user=user) copied_workflow.steps = copied_steps + + copied_comments = [] + for comment in self.comments: + copied_comments.append(comment.copy()) + + # copy comment relationships + for old_comment, new_comment in zip(self.comments, copied_comments): + for step_id in [step.order_index for step in old_comment.child_steps]: + child_step = copied_workflow.steps[step_id] + if child_step: + child_step.parent_comment = new_comment + + for comment_id in [comment.order_index for comment in old_comment.child_comments]: + child_comment = copied_workflow.comments[comment_id] + if child_comment: + child_comment.parent_comment = new_comment + + copied_workflow.comments = copied_comments + return copied_workflow @property @@ -8266,6 +8285,17 @@ def from_dict(dict): comment.data = dict.get("data", None) return comment + def copy(self): + comment = WorkflowComment() + comment.order_index = self.order_index + comment.type = self.type + comment.position = self.position + comment.size = self.size + comment.color = self.color + comment.data = self.data + + return comment + class StoredWorkflowUserShareAssociation(Base, UserShareAssociation): __tablename__ = "stored_workflow_user_share_connection" From f9b2a68ce4c48fa48a35faf6020ac7bc83ebf846 Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:25:50 +0200 Subject: [PATCH 2/3] use dict instead of relying on list order --- lib/galaxy/model/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 9de5be22593a..d592f9308bfa 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -7712,15 +7712,18 @@ def copy(self, user=None): for comment in self.comments: copied_comments.append(comment.copy()) + steps_by_id = {s.order_index: s for s in copied_workflow.steps} + comments_by_id = {c.order_index: c for c in copied_workflow.comments} + # copy comment relationships for old_comment, new_comment in zip(self.comments, copied_comments): for step_id in [step.order_index for step in old_comment.child_steps]: - child_step = copied_workflow.steps[step_id] + child_step = steps_by_id.get(step_id) if child_step: child_step.parent_comment = new_comment for comment_id in [comment.order_index for comment in old_comment.child_comments]: - child_comment = copied_workflow.comments[comment_id] + child_comment = comments_by_id.get(comment_id) if child_comment: child_comment.parent_comment = new_comment From 69fb6cee1f3937a382ed63e847618a77ffb46add Mon Sep 17 00:00:00 2001 From: Laila Los <44241786+ElectronicBlueberry@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:41:42 +0200 Subject: [PATCH 3/3] fix comments used before assigned --- lib/galaxy/model/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index d592f9308bfa..40a8d414f8c9 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -7708,12 +7708,9 @@ def copy(self, user=None): old_step.copy_to(new_step, step_mapping, user=user) copied_workflow.steps = copied_steps - copied_comments = [] - for comment in self.comments: - copied_comments.append(comment.copy()) - + copied_comments = [comment.copy() for comment in self.comments] steps_by_id = {s.order_index: s for s in copied_workflow.steps} - comments_by_id = {c.order_index: c for c in copied_workflow.comments} + comments_by_id = {c.order_index: c for c in copied_comments} # copy comment relationships for old_comment, new_comment in zip(self.comments, copied_comments):