From 0f48833d8d06e5442c2cf74afd53a2f263ceccae 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 eded16a1d7a..7c241aed7db 100644 --- a/app/models/form/import.rb +++ b/app/models/form/import.rb @@ -200,8 +200,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? @@ -209,7 +211,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 a266374eba7..06b146c431e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1709,6 +1709,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