From 818e16b234295fff19303a4fc7a6696bbb76e342 Mon Sep 17 00:00:00 2001 From: mfo Date: Fri, 30 Aug 2024 11:39:50 +0200 Subject: [PATCH] fix(delete_orphaned_champs_with_missing_dossier): must reload champ before destroying when plucked. also rescue error when repetition chidren is destroyed after parent --- ...15_delete_orphaned_champs_with_missing_dossier.rake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/tasks/deployment/20240827085815_delete_orphaned_champs_with_missing_dossier.rake b/lib/tasks/deployment/20240827085815_delete_orphaned_champs_with_missing_dossier.rake index 890d1ae72..eaa382060 100644 --- a/lib/tasks/deployment/20240827085815_delete_orphaned_champs_with_missing_dossier.rake +++ b/lib/tasks/deployment/20240827085815_delete_orphaned_champs_with_missing_dossier.rake @@ -6,8 +6,14 @@ namespace :after_party do puts "Running deploy task 'delete_orphaned_champs_with_missing_dossier'" Champ.select(:id, :type).where.missing(:dossier).each do |champ| - champ.champs.destroy_all if champ.type == 'Champs::RepetitionChamp' - champ.destroy + begin + champ.reload + champ.champs.destroy_all if champ.type == 'Champs::RepetitionChamp' + champ.destroy + rake_puts "succeed with: #{champ.id}" + rescue ActiveRecord::RecordNotFound + rake_puts "failed with: #{champ.id}" + end end # Update task as completed. If you remove the line below, the task will