diff --git a/app/models/task.rb b/app/models/task.rb index 88264920567..b137d902b01 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -503,15 +503,13 @@ def verify_user_can_update!(user) end def reassign(reassign_params, current_user) - sibling = Task.create!( - attributes.merge( - id: nil, - assigned_by_id: self.class.child_assigned_by_id(parent, current_user), - assigned_to: self.class.child_task_assignee(parent, reassign_params), - instructions: flattened_instructions(reassign_params), - status: Constants.TASK_STATUSES.assigned - ) - ) + sibling = dup.tap do |task| + task.assigned_by_id = self.class.child_assigned_by_id(parent, current_user) + task.assigned_to = self.class.child_task_assignee(parent, reassign_params) + task.instructions = flattened_instructions(reassign_params) + task.status = Constants.TASK_STATUSES.assigned + task.save! + end # Preserve the open children and status of the old task children.select(&:stays_with_reassigned_parent?).each { |child| child.update!(parent_id: sibling.id) }