From cb7a19b0987b68728595ed6af86d85c1994f36f2 Mon Sep 17 00:00:00 2001 From: Kat Tipton Date: Thu, 16 Jan 2020 13:04:33 -0500 Subject: [PATCH] Wrap cancel tree in transaction --- app/models/task.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/task.rb b/app/models/task.rb index 0ff451edfe2..c42322eef04 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -533,12 +533,15 @@ def cancel_task_and_child_subtasks # by avoiding callbacks, we aren't saving PaperTrail versions # Manually save the state before and after. tasks = Task.open.where(id: descendant_ids) - tasks.each { |task| task.paper_trail.save_with_version } - tasks.update_all( - status: Constants.TASK_STATUSES.cancelled, - closed_at: Time.zone.now - ) - tasks.each { |task| task.reload.paper_trail.save_with_version } + + transaction do + tasks.each { |task| task.paper_trail.save_with_version } + tasks.update_all( + status: Constants.TASK_STATUSES.cancelled, + closed_at: Time.zone.now + ) + tasks.each { |task| task.reload.paper_trail.save_with_version } + end end def timeline_title