Project

General

Profile

Error on Issue CSV Export

Added by Robert Morbitzer about 4 years ago

If I want to export my Issues with the CSV Option on the right bottom, it opens the properties for the export.

After that, regardless what I choose as options and click on "Export" I got an Internal Error.

Error from production Log:

Started GET "/redmine/projects/test/issues.csv?utf8=%E2%9C%93&set_filter=1&f%5B%5D=status_id&op%5Bstatus_id%5D=o&v%5Bstatus_id%5D%5B%5D=&c%5B%5D=id&c%5B%5D=tracker&c%5B%5D=project&c%5B%5D=status&c%5B%5D=subject&c%5B%5D=assigned_to&c%5B%5D=cf_16&c%5B%5D=cf_18&sort=id%3Adesc&c%5B%5D=&encoding=ISO-8859-1" for x.x.x.x at 2020-08-07 10:48:39 +0200
Processing by IssuesController#index as CSV
Parameters: {"utf8"=>"✓", "set_filter"=>"1", "f"=>["status_id"], "op"=>{"status_id"=>"o"}, "v"=>{"status_id"=>[""]}, "c"=>["id", "tracker", "project", "status", "subject", "assigned_to", "cf_16", "cf_18", ""], "sort"=>"id:desc", "encoding"=>"ISO-8859-1", "project_id"=>"test"}
Current user: robert.morbitzer (id=75)
Completed 500 Internal Server Error in 26ms (ActiveRecord: 7.1ms)

FrozenError (can't modify frozen String: ""):

lib/redmine/codeset_util.rb:59:in `force_encoding'
lib/redmine/codeset_util.rb:59:in `from_utf8'
lib/redmine/export/csv.rb:52:in `block in <<'
lib/redmine/export/csv.rb:49:in `map'
lib/redmine/export/csv.rb:49:in `<<'
app/helpers/queries_helper.rb:283:in `block (2 levels) in query_to_csv'
app/helpers/queries_helper.rb:282:in `each'
app/helpers/queries_helper.rb:282:in `block in query_to_csv'
lib/redmine/export/csv.rb:44:in `generate'
lib/redmine/export/csv.rb:26:in `generate'
app/helpers/queries_helper.rb:278:in `query_to_csv'
app/controllers/issues_controller.rb:67:in `block (2 levels) in index'
app/controllers/issues_controller.rb:47:in `index'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

My system:

Environment:
Redmine version 4.0.6.stable
Ruby version 2.7.0-p0 (2019-12-25) [x86_64-linux-gnu]
Rails version 5.2.4.3
Environment production
Database adapter Mysql2
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
SCM:
Git 2.25.1
Filesystem
Redmine plugins:
redmine_checklists 3.1.16
redmine_contacts 4.3.1
redmine_contacts_helpdesk 4.1.9
redmine_contacts_invoices 4.2.3
redmine_favorite_projects 2.1.0
redmine_timesheet_plugin 0.7.0

I would appreciate any help. I searched many forums for a solution so far.


Replies (11)

RE: Error on Issue CSV Export - Added by Robert Morbitzer about 4 years ago

Hey guys,

I installed a new Redmine Instance, where I use MySQL 5.7 and Ruby 2.6.5. I created the Passenger Module for Apache with the Ruby Gem for Passenger.

After that, all works as expected.

Best Regards
Robert

RE: Error on Issue CSV Export - Added by Darko Palic over 3 years ago

I am having exactly the same issue on Ubuntu 20.04 and the default redmine setup 4.0.6 with ruby 2.7.0p0

did someone solve the installation on Ubuntu 20.04?

RE: Error on Issue CSV Export - Added by Darko Palic over 3 years ago

cannot say for sure since stacktrace is missing.
But I can say I am not using redmineUP so probably it is something else. My stacktrace looks like the posted one on this thread.

RE: Error on Issue CSV Export - Added by Robert Morbitzer over 3 years ago

Darko Palic wrote:

I am having exactly the same issue on Ubuntu 20.04 and the default redmine setup 4.0.6 with ruby 2.7.0p0

did someone solve the installation on Ubuntu 20.04?

Redmine 4.0.6 does not support Ruby 2.7.0p0 as described here https://www.redmine.org/projects/redmine/wiki/RedmineInstall.
Only Ruby 2.6.0 is supported.

I'm using this working environment:

Redmine version                4.1.1.stable.19939
Ruby version 2.6.5-p114 (2019-10-01) [x86_64-linux]
Rails version 5.2.4.2

RE: Error on Issue CSV Export - Added by Darko Palic over 3 years ago

what is funny, since redmine is provided by ubuntu
https://packages.ubuntu.com/focal/redmine and it is provided by ruby 2.7

RE: Error on Issue CSV Export - Added by Robert Morbitzer over 3 years ago

I had problems with the redmine package provided by the ubuntu repositories.

So i installed the Package from the Redmine Page.

Also the passenger version in the repositories causes me problems.

Passenger is a Ruby gem in my environment.

RE: Error on Issue CSV Export - Added by Darko Palic about 3 years ago

Robert Morbitzer wrote:

I had problems with the redmine package provided by the ubuntu repositories.

So i installed the Package from the Redmine Page.

Also the passenger version in the repositories causes me problems.

Passenger is a Ruby gem in my environment.

do you have a manual how to install it on ubuntu like you did?
I am also about to get rid of ubuntu managed redmine, but unclear what I need to do in ubuntu

RE: Error on Issue CSV Export - Added by Marc Olzheim over 2 years ago

I ran into the same issue and ended up hotpatching /usr/share/redmine/lib/redmine/codeset_util.rb line 59 to:

str = str.dup.force_encoding('UTF-8')

RE: Error on Issue CSV Export - Added by rob buzzai 7 months ago

Hi, following Marc reply, I fixed the issue on redmine version 4.0.6 stable, with the following code on codeset_util.rb

module Redmine
  module CodesetUtil

    def self.replace_invalid_utf8(str)
      return str if str.nil?
      str.dup.force_encoding('UTF-8')
      if ! str.valid_encoding?
        str = str.encode("UTF-16LE", :invalid => :replace,
              :undef => :replace, :replace => '?').encode("UTF-8")
      end
      str
    end

    def self.to_utf8(str, encoding)
      return str if str.nil?
      str.dup.force_encoding("ASCII-8BIT")
      if str.empty?
        str.dup.force_encoding("UTF-8")
        return str
      end
      enc = encoding.blank? ? "UTF-8" : encoding
      if enc.upcase != "UTF-8" 
        str.dup.force_encoding(enc)
        str = str.encode("UTF-8", :invalid => :replace,
              :undef => :replace, :replace => '?')
      else
        str = replace_invalid_utf8(str)
      end
      str
    end

    def self.to_utf8_by_setting(str)
      return str if str.nil?
      self.to_utf8_by_setting_internal(str).force_encoding('UTF-8')
    end

    def self.to_utf8_by_setting_internal(str)
      return str if str.nil?
      str.dup.force_encoding('ASCII-8BIT')
      return str if str.empty?
      return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
      str.dup.force_encoding('UTF-8')
      encodings = Setting.repositories_encodings.split(',').collect(&:strip)
      encodings.each do |encoding|
        begin
          str.dup.force_encoding(encoding)
          utf8 = str.encode('UTF-8')
          return utf8 if utf8.valid_encoding?
        rescue
          # do nothing here and try the next encoding
        end
      end
      self.replace_invalid_utf8(str).force_encoding('UTF-8')
    end

    def self.from_utf8(str, encoding)
      str ||= ''
      str.dup.force_encoding('UTF-8')
      if encoding.upcase != 'UTF-8'
        str = str.encode(encoding, :invalid => :replace,
                         :undef => :replace, :replace => '?')
      else
        str = self.replace_invalid_utf8(str)
      end
    end
  end
end


RE: Error on Issue CSV Export - Added by Holger Just 7 months ago

This change will cause some of the logic of the methods to be disabled. In the end, your changes have the same effect as deleting the force_encoding lines would have (namely turning it into a no-op). This will result in some changed behavior and may cause unexpected encoding results for non-UTF-8-encoded strings. This change should thus NOT be used.

Instead, if you still observe an issue with an up-to-date version of Redmine in this area, please open an issue and provide enough details there to allow us to reproduce the issue, this included:

  • Your Redmine and Ruby versions
  • a full stack trace
  • a detailed description of the involved data and your setup to allow us to reproduce the issue.

Please also see Submissions for details.

    (1-11/11)