A platform for community discussion. Free, open, simple.
FIX: CSV Exports were throwing errors with invalid dates
Robin Wardce663d67e1e6
diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rbindex 39f9c565b12..6092fb1a65f 100644--- a/app/jobs/regular/export_csv_file.rb+++ b/app/jobs/regular/export_csv_file.rb@@ -182,8 +182,14 @@ module Jobsdef report_exportreturn enum_for(:report_export) unless block_given?- @extra[:start_date] = @extra[:start_date].to_date.beginning_of_day if @extra[:start_date].is_a?(String)- @extra[:end_date] = @extra[:end_date].to_date.end_of_day if @extra[:end_date].is_a?(String)+ # If dates are invalid consider then `nil`+ if @extra[:start_date].is_a?(String)+ @extra[:start_date] = @extra[:start_date].to_date.beginning_of_day rescue nil+ end+ if @extra[:end_date].is_a?(String)+ @extra[:end_date] = @extra[:end_date].to_date.end_of_day rescue nil+ end+@extra[:filters] = {}if @extra[:category_id].present?@extra[:filters][:category] = @extra[:category_id].to_idiff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rbindex 62ffb151ba8..8322265a729 100644--- a/spec/jobs/export_csv_file_spec.rb+++ b/spec/jobs/export_csv_file_spec.rb@@ -85,6 +85,14 @@ describe Jobs::ExportCsvFile doexporterend+ it "does not throw an error when the dates are invalid" do+ Jobs::ExportCsvFile.new.execute(+ entity: 'report',+ user_id: user.id,+ args: { start_date: 'asdfasdf', end_date: 'not-a-date', name: 'dau_by_mau' }+ )+ end+it 'works with single-column reports' douser.user_visits.create!(visited_at: '2010-01-01', posts_read: 42)Fabricate(:user).user_visits.create!(visited_at: '2010-01-03', posts_read: 420)