From 1693e46acb076dd7b36d10939aaf170bc3256673 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 7 Feb 2023 10:52:43 +0100 Subject: [PATCH] fix(dossier): prevent crash when updating champs in rebase --- app/models/concerns/dossier_rebase_concern.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/dossier_rebase_concern.rb b/app/models/concerns/dossier_rebase_concern.rb index 0eb9ab643..1729f6918 100644 --- a/app/models/concerns/dossier_rebase_concern.rb +++ b/app/models/concerns/dossier_rebase_concern.rb @@ -77,9 +77,11 @@ module DossierRebaseConcern # due to repetition tdc clone on update or erase # we must reassign tdc to the latest version - champs_by_stable_id - .filter_map { |stable_id, champs| [target_coordinates_by_stable_id[stable_id].type_de_champ_id, champs] if champs.present? } - .each { |type_de_champ_id, champs| champs.update_all(type_de_champ_id:) } + champs_by_stable_id.each do |stable_id, champs| + if target_coordinates_by_stable_id[stable_id].present? && champs.present? + champs.update_all(type_de_champ_id: target_coordinates_by_stable_id[stable_id].type_de_champ_id) + end + end # update dossier revision update_column(:revision_id, target_revision.id)