Project

General

Profile

Actions

Defect #19316

closed

CustomField#possible_values may raise undefined method `force_encoding' error

Added by Dmitry Repkin about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Urgent
Category:
Custom fields
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

After upgrading to 3.0 Redmine stops working.

Here are the lines from log file:

Started GET "/issues/2598" for 127.0.0.1 at 2015-03-10 01:11:24 +0300
Processing by IssuesController#show as HTML
  Parameters: {"id"=>"2598"}
  Current user: rd (id=1)
Completed 500 Internal Server Error in 40ms

NoMethodError (undefined method `force_encoding' for 1.0:Float):
  app/models/custom_field.rb:121:in `block in possible_values'
  app/models/custom_field.rb:120:in `each'
  app/models/custom_field.rb:120:in `possible_values'
  lib/redmine/field_format.rb:528:in `possible_values_options'
  lib/redmine/field_format.rb:463:in `query_filter_options'
  app/models/query.rb:791:in `add_custom_field_filter'
  app/models/query.rb:813:in `block in add_custom_fields_filters'
  app/models/query.rb:812:in `add_custom_fields_filters'
  app/models/issue_query.rb:237:in `initialize_available_filters'
  app/models/query.rb:353:in `available_filters'
  app/models/query.rb:395:in `type_for'
  app/models/query.rb:259:in `block in validate_query_filters'
  app/models/query.rb:257:in `each_key'
  app/models/query.rb:257:in `validate_query_filters'
  app/models/query.rb:594:in `statement'
  app/models/issue_query.rb:362:in `issue_ids'
  app/controllers/issues_controller.rb:353:in `retrieve_previous_and_next_issue_ids'
  app/controllers/issues_controller.rb:117:in `block (2 levels) in show'
  app/controllers/issues_controller.rb:115:in `show'

As you could see the '1.0' string incorrectly treated as 'Float' and could not be converted.

I found the r13482 introduce this problem:

--- custom_field.rb    (revision 13481)
+++ custom_field.rb    (revision 13482)
@@ -117,7 +118,7 @@
     values = read_attribute(:possible_values)
     if values.is_a?(Array)
       values.each do |value|
-        value.force_encoding('UTF-8') if value.respond_to?(:force_encoding)
+        value.force_encoding('UTF-8')
       end
       values
     else

Reverting the line to previous code resolves the issue.

Actions

Also available in: Atom PDF