Skip to content

Private space user CSV import fails when using an incorrect column separator #8298

@ahukkanen

Description

@ahukkanen

Describe the bug
When trying to import private space users from a CSV file with semicolon separators, the system will throw the following exception:

NoMethodError in Decidim::ParticipatoryProcesses::Admin::ParticipatorySpacePrivateUsersCsvImportsController#create

undefined method `match?' for nil:NilClass

To Reproduce
Steps to reproduce the behavior:

  1. Go to admin panel
  2. Go to one of the processes
  3. Go to "Private participants"
  4. Click "Import via CSV"
  5. Provide the users.csv file provided below
  6. Click "Upload"
  7. See the error

Example CSV file for testing (save this as users.csv:

john.doe@example.org;John Doe
joanna.doe@example.org;Joanna Doe

Expected behavior
I would expect the import page to show a sensible error message instead of "An error occurred on the serve".

If it is possible to detect the wrong column separator, the best would be to guide the user towards correcting the mistake. If not, the user could be guided to check what might be wrong (e.g. "Check that the column separator is a comma (',').")

Screenshots
N/A

Stacktrace

undefined method `match?' for nil:NilClass

decidim-admin (0.24.3) app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb:21:in `block in validate_csv'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:1122:in `emit_row'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:871:in `block in parse_quotable_loose'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:52:in `block in each_line'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:49:in `each_line'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:49:in `each_line'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:823:in `parse_quotable_loose'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv/parser.rb:336:in `parse'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv.rb:1280:in `each'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv.rb:1280:in `each'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv.rb:511:in `block in foreach'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv.rb:658:in `open'
/.../.rbenv/versions/2.7.3/lib/ruby/2.7.0/csv.rb:510:in `foreach'
decidim-admin (0.24.3) app/forms/decidim/admin/participatory_space_private_user_csv_import_form.rb:20:in `validate_csv'

Extra data (please complete the following information):

  • Device: (any)
  • Device OS: (any)
  • Browser: (any)
  • Decidim Version: 0.24.x, 0.25.x, develop
  • Decidim installation: (any)

Additional context
Slightly related to #7240

There have been some import functionality improvements at #7084 and #8271 which create a programming API for the importers. Maybe the same functionality could be centralized to the APIs these PRs provide in order to make the importing functionality more consistent (e.g. when to use a comma and when a semicolon as a separator, different importers differ right now). Another benefit would be that the APIs also provide import functionality for other file formats, such as XLSX and JSON.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions