Defect #4745

Bug in index.xml.builder (issues)

Added by Yohann Monnier almost 8 years ago. Updated over 7 years ago.

Status:ClosedStart date:2010-02-05
Priority:NormalDue date:
Assignee:Eric Davis% Done:

100%

Category:REST API
Target version:1.0.0 (RC)
Resolution:Fixed Affected version:

Description

in this file at :

xml.issues :type => 'array' , :count => @issue_count do

The ":count" parameter will cause an error calling issues from activeresource :

can't typecast "1" 
 ["/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value'", "/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:208:in `typecast_xml_value'", "/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:199:in `inject'",

If you delete this parameter, all is working fine.

My configuration

Ruby version 1.8.7 (i486-linux)
RubyGems version 1.3.5
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root /var/www/redmine
Environment development
Database adapter postgresql
Database schema version 20091227112908


Related issues

Related to Redmine - Feature #6140: REST issues response with issue count limit and offset Closed 2010-08-13
Duplicated by Redmine - Defect #5226: 'can't typecast' in REST API for issues Closed 2010-03-31

Associated revisions

Revision 3631
Added by Eric Davis over 7 years ago

Removed count from issues.xml. It causes a typecast error in ActiveResource. (#4745)

History

#1 Updated by Artem Kulyabin almost 8 years ago

REST API bug?

I tried to run the script http://www.redmine.org/wiki/redmine/Rest_api_with_ruby. Displays an error message: /home/artem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value': can't typecast "2" (RuntimeError)

I deleted :count => @issue_count in app/views/issues/index.xml.builder and all earned.

#2 Updated by Artem Kulyabin almost 8 years ago

I wrote a script rest.rb:

require 'rubygems'
require 'active_resource'

class Issue < ActiveResource::Base
   self.site = 'http://www.redmine.org/'   
end

issues = Issue.find(:all)
puts issues.first.subject

$ ruby rest.rb
/home/artem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value': can't typecast "1794" (RuntimeError)

#3 Updated by Artem Kulyabin almost 8 years ago

I wrote a script rest2.rb:

require 'rubygems'
require 'active_resource'

class Project < ActiveResource::Base
   self.site = 'http://www.redmine.org/'   
end

projects = Project.find(:all)
puts projects.first.name

$ ruby rest2.rb
Redmine

It works!

#4 Updated by Yohann Monnier almost 8 years ago

thats what i said, if you delete the :count parameter, all is working fine !

#5 Updated by Eric Davis over 7 years ago

  • Category set to REST API
  • Status changed from New to Closed
  • Assignee set to Eric Davis
  • Target version set to 1.0.0 (RC)
  • % Done changed from 0 to 100
  • Resolution set to Fixed

I've removed the count attribute in issues.xml. It's not ideal because of the pagination won't show all of the issues but it breaks ActiveResource.

Here's the full error for the search:

RuntimeError: can't typecast "368" 
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:208:in `typecast_xml_value'
        from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `inject'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `each'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `inject'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `typecast_xml_value'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
        from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/formats/xml_format.rb:19:in `decode'
        from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/connection.rb:138:in `get'
        from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/base.rb:639:in `find_every'
        from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/base.rb:582:in `find'
        from (irb):5
        from :0

Also available in: Atom PDF