Project

General

Profile

Actions

Defect #19316

closed

CustomField#possible_values may raise undefined method `force_encoding' error

Added by Dmitry Repkin almost 10 years ago. Updated almost 10 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 #1

Updated by Toshi MARUYAMA almost 10 years ago

  • Target version set to 3.0.1
Actions #2

Updated by Toshi MARUYAMA almost 10 years ago

  • Description updated (diff)
Actions #3

Updated by Jean-Philippe Lang almost 10 years ago

  • Status changed from New to Needs feedback

How did you get a float value in possible values? If #possible_values returns non string values, it won't work with regular list custom fields. So the proper fix should rather be:

Index: app/models/custom_field.rb
===================================================================
--- app/models/custom_field.rb    (revision 14067)
+++ app/models/custom_field.rb    (working copy)
@@ -118,7 +118,7 @@
     values = read_attribute(:possible_values)
     if values.is_a?(Array)
       values.each do |value|
-        value.force_encoding('UTF-8')
+        value.to_s.force_encoding('UTF-8')
       end
       values
     else
Actions #4

Updated by Dmitry Repkin almost 10 years ago

Jean-Philippe Lang wrote:

How did you get a float value in possible values? If #possible_values returns non string values, it won't work with regular list custom fields.

So it stops working in 3.0; even 'Issues' list stops to show. It seems it is a 'Affected versions' custom field, which contains '1.0' element in list.

I've checked 'to_s' patch, all works fine.

Actions #5

Updated by Jean-Philippe Lang almost 10 years ago

  • Subject changed from Problem with 'force_encoding' to CustomField#possible_values may raise undefined method `force_encoding' error
  • Status changed from Needs feedback to Resolved
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

This should be fixed in r14079, thanks for the feedback.

Actions #6

Updated by Jean-Philippe Lang almost 10 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF