From 062d07ddc2ff791711195794024ae9ecbdc550c1 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 6 Jun 2025 10:52:44 +0100 Subject: [PATCH] ensure nil locations are never overwritten --- app/services/merge/merge_organisations_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/merge/merge_organisations_service.rb b/app/services/merge/merge_organisations_service.rb index 40749b54c..feef10245 100644 --- a/app/services/merge/merge_organisations_service.rb +++ b/app/services/merge/merge_organisations_service.rb @@ -102,7 +102,11 @@ private location_to_set = scheme_to_set.locations.find_by(name: lettings_log.location&.name, postcode: lettings_log.location&.postcode) lettings_log.scheme = scheme_to_set if scheme_to_set.present? - lettings_log.location = location_to_set if location_to_set.present? + # in some cases the lettings_log location is nil even if scheme is present (they're two different questions). + # in certain cases the location_to_set query can find a location in the scheme with nil values for name and postcode, + # so we can end up setting the location to non nil. + # hence the extra check here + lettings_log.location = location_to_set if location_to_set.present? && lettings_log.location.present? end lettings_log.owning_organisation = @absorbing_organisation lettings_log.managing_organisation = @absorbing_organisation if lettings_log.managing_organisation == merging_organisation