Defect #34326

CSV import raises an exception if CSV header has empty columns

Added by Go MAEDA 11 months ago. Updated 11 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Importers
Target version:-
Resolution:Fixed Affected version:

Description

To reproduce the error, attempt to import issues from the attached csv file (issues.csv). In the CSV file, the second column of the header is blank.

You will see an error page after clicking the "Next" button on the import options page.

Started GET "/imports/ad8c66039d97b44886137856ade5f856/mapping" for 127.0.0.1 at 2020-11-27 14:51:09 +0900
Processing by ImportsController#mapping as HTML
  Parameters: {"id"=>"ad8c66039d97b44886137856ade5f856"}
.
.
.
NoMethodError (undefined method `downcase' for nil:NilClass):

app/controllers/imports_controller.rb:177:in `map'
app/controllers/imports_controller.rb:177:in `auto_map_fields'
app/controllers/imports_controller.rb:70:in `mapping'
lib/redmine/sudo_mode.rb:61:in `sudo_mode'

issues.csv Magnifier (499 Bytes) Go MAEDA, 2020-11-27 06:47

fixed-34326.patch Magnifier (3.6 KB) Yuichi HARADA, 2020-11-30 08:41

34326-v2.patch Magnifier (1.32 KB) Go MAEDA, 2020-12-03 15:11


Related issues

Related to Redmine - Feature #22913: Auto-select fields mapping in Importing Closed

Associated revisions

Revision 20576
Added by Go MAEDA 11 months ago

CSV import raises an exception if CSV header has empty columns (#22913, #34326).

History

#1 Updated by Go MAEDA 11 months ago

  • Related to Feature #22913: Auto-select fields mapping in Importing added

#2 Updated by Yuichi HARADA 11 months ago

I created a patch. No exception is raised if there are blank columns in the CSV header.

diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 9431ca098..a5248dc1e 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -173,7 +173,7 @@ class ImportsController < ApplicationController
     return if @import.settings['encoding'].blank?

     mappings = @import.settings['mapping'] ||= {}
-    headers = @import.headers.map(&:downcase)
+    headers = @import.headers.map{|header| header.to_s.downcase}

     # Core fields
     import_type::AUTO_MAPPABLE_FIELDS.each do |field_nm, label_nm|

#3 Updated by Go MAEDA 11 months ago

Yuichi HARADA wrote:

I created a patch. No exception is raised if there are blank columns in the CSV header.

[...]

Thank you for the patch. I think the test can be simplified by putting the blank column at the end.

#4 Updated by Yuichi HARADA 11 months ago

Go MAEDA wrote:

Yuichi HARADA wrote:

I created a patch. No exception is raised if there are blank columns in the CSV header.

[...]

Thank you for the patch. I think the test can be simplified by putting the blank column at the end.

Thank you for your point. I think it's good because you can detect test failures without changing the test.

#5 Updated by Go MAEDA 11 months ago

  • Target version set to 4.2.0

Setting the target version to 4.2.0.

#6 Updated by Go MAEDA 11 months ago

  • Subject changed from CSV import raises an exception if CSV header has blank columns to CSV import raises an exception if CSV header has empty columns
  • Assignee set to Go MAEDA
  • Target version deleted (4.2.0)
  • Resolution set to Fixed

Committed the fix as a part of #22913. Thank you.

#7 Updated by Go MAEDA 11 months ago

  • Status changed from New to Closed

Also available in: Atom PDF