From 59e2ef27f812d278aed11a3347a0a927473db5ab Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 10 Sep 2026 12:14:18 +0000 Subject: [PATCH] Fix 500 error when trying to upload a non-custom-filter JSON import (#40449) --- app/models/form/import.rb | 9 +++++++-- config/locales/en.yml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/form/import.rb b/app/models/form/import.rb index e3ad5f8f1e..6893cbb340 100644 --- a/app/models/form/import.rb +++ b/app/models/form/import.rb @@ -202,8 +202,10 @@ class Form::Import end def validate_json_data + return errors.add(:data, I18n.t('imports.errors.incompatible_type')) unless allowed_type_for_json? + return errors.add(:date, I18n.t('imports.errors.no_data')) if json_data.empty? + errors.add(:data, I18n.t('imports.errors.over_rows_processing_limit', count: ROWS_PROCESSING_LIMIT)) if json_data.count > ROWS_PROCESSING_LIMIT - errors.add(:data, I18n.t('imports.errors.incompatible_type')) unless allowed_type_for_json? end def content_type_is_json? @@ -211,7 +213,10 @@ class Form::Import end def json_data - parse_json['custom_filters'].map(&:deep_symbolize_keys) + case type.to_sym + when :custom_filters + parse_json['custom_filters'].map(&:deep_symbolize_keys) + end end def parse_json diff --git a/config/locales/en.yml b/config/locales/en.yml index 0b9115aba1..acaf60f73d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1692,6 +1692,7 @@ en: incompatible_type: Incompatible with the selected import type invalid_csv_file: 'Invalid CSV file. Error: %{error}' invalid_json_file: 'Invalid JSON file. Error: %{error}' + no_data: This file does not contain any data matching the given import type over_rows_processing_limit: contains more than %{count} rows status_not_found_warning: Some of your filters hide specific posts that are not known by this server. These posts will not be automatically filtered if they are discovered later by the server. too_large: File is too large