diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 54305c2cc116..d78689534474 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -7705,6 +7705,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 = [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_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 = 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 = comments_by_id.get(comment_id) + if child_comment: + child_comment.parent_comment = new_comment + + copied_workflow.comments = copied_comments + return copied_workflow @property @@ -8264,6 +8283,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"