From d3219b9ba3055c6c4ea4dcb87944570251790090 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 12 Mar 2025 14:34:35 +0000 Subject: [PATCH 1/3] Add error handling for JSON parsing in UPRN client (#2989) * Add error handling for JSON parsing in UPRN client * Update error handling * Update error handling 2 --- app/services/uprn_client.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/services/uprn_client.rb b/app/services/uprn_client.rb index 97dc4753f..f170ba3a0 100644 --- a/app/services/uprn_client.rb +++ b/app/services/uprn_client.rb @@ -20,7 +20,14 @@ class UprnClient end def result - @result ||= JSON.parse(response.body).dig("results", 0, "DPA") || JSON.parse(response.body).dig("results", 0, "LPI") + @result ||= if response.is_a?(Net::HTTPSuccess) + parsed_response = JSON.parse(response.body) + parsed_response.dig("results", 0, "DPA") || parsed_response.dig("results", 0, "LPI") + else + Rails.logger.error("Response code: #{response.code}") + Rails.logger.error("Response body: #{response.body}") + nil + end end private From 0dff6f2fa359af49c64422982788608c9c28b392 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:40:18 +0000 Subject: [PATCH 2/3] Skip bulk error (#2986) --- app/models/validations/sales/property_validations.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 7fd4d2440..56a09c36f 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -49,9 +49,9 @@ module Validations::Sales::PropertyValidations record.errors.add :uprn_confirmation, I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england") record.errors.add :uprn_selection, I18n.t("validations.sales.property_information.uprn_selection.not_in_england") if record.uprn.present? - record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.address_not_in_england") + record.errors.add :saledate, :skip_bu_error, message: I18n.t("validations.sales.property_information.saledate.address_not_in_england") else - record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.postcode_not_in_england") + record.errors.add :saledate, :skip_bu_error, message: I18n.t("validations.sales.property_information.saledate.postcode_not_in_england") end end end From 772b1fcd68cc92d1472459bc01c11c5f3f25c604 Mon Sep 17 00:00:00 2001 From: carolynbarker <8038496+carolynbarker@users.noreply.github.com> Date: Wed, 12 Mar 2025 17:02:27 +0000 Subject: [PATCH 3/3] CLDC-3911 Limit CSV variables to those defined in or before year (#2982) * don't use variables from the future * filter out nil elements for vars only defined in future * only group variables by name, not by description --------- Co-authored-by: Carolyn --- app/services/csv/lettings_log_csv_service.rb | 7 +++---- app/services/csv/sales_log_csv_service.rb | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/services/csv/lettings_log_csv_service.rb b/app/services/csv/lettings_log_csv_service.rb index 0a187d524..d7ab101ac 100644 --- a/app/services/csv/lettings_log_csv_service.rb +++ b/app/services/csv/lettings_log_csv_service.rb @@ -284,13 +284,12 @@ module Csv end def lettings_log_definitions - CsvVariableDefinition.lettings.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.lettings.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.compact end def insert_derived_and_related_attributes(ordered_questions) diff --git a/app/services/csv/sales_log_csv_service.rb b/app/services/csv/sales_log_csv_service.rb index 08ce178e3..35adcf27f 100644 --- a/app/services/csv/sales_log_csv_service.rb +++ b/app/services/csv/sales_log_csv_service.rb @@ -179,13 +179,12 @@ module Csv end def sales_log_definitions - CsvVariableDefinition.sales.group_by { |record| [record.variable, record.definition] } - .map do |_, options| + CsvVariableDefinition.sales.group_by(&:variable).map { |_, options| exact_match = options.find { |definition| definition.year == @year } next exact_match if exact_match - options.max_by(&:year) - end + options.select { |opt| opt.year < @year }.max_by(&:year) + }.compact end def insert_derived_and_related_attributes(ordered_questions)