Skip to content

CSV export fails when (sub-)project name contains whitespaces #64

Open
@catabu1

Description

@catabu1

Only confirmed for subprojects. There is a problem when the timesheet should be exported to csv and the time_entries are sorted by project.

The following is a related entry from the production log:

Completed 500 Internal Server Error in 227ms (ActiveRecord: 47.0ms)

NoMethodError (undefined method `name' for "Project / Subproject with Whitespaces":String):
  app/models/project.rb:551:in `<=>'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `<=>'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `sort'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:159:in `block in to_csv'
  plugins/redmine_timesheet_plugin/app/models/timesheet.rb:153:in `to_csv'
  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:87:in `block (2 levels) in report'
  plugins/redmine_timesheet_plugin/app/controllers/timesheet_controller.rb:85:in `report'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'
  plugins/redmine_dmsf/lib/redmine_dmsf/webdav/no_parse.rb:33:in `call'

I changed the line that's sorting the entries in the method to_csv to the following, which fixed my issues:

diff --git a/app/models/timesheet.rb b/app/models/timesheet.rb
index 84196d9..0e7b43e 100644
--- a/app/models/timesheet.rb
+++ b/app/models/timesheet.rb
@@ -162,7 +162,7 @@ class Timesheet
           end
         end
       when :issue
-        time_entries.sort.each do |project, entries|
+        time_entries.sort {|a,b| a[0].to_s <=> b[0].to_s}.each do |project, entries|
           entries[:issues].sort {|a,b| a[0].id <=> b[0].id}.each do |issue, time_entries|
             time_entries.each do |e|
               csv << time_entry_to_csv(e)

I'm no expert on ruby and I don't know if that's the cleanest solution possible (hence no pull request), but that's what fixed it for me for now.

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