Defect #4745

Bug in index.xml.builder (issues)

Added by Yohann Monnier about 2 years ago. Updated almost 2 years ago.

Status:Closed Start date:2010-02-05
Priority:Normal Due date:
Assignee:Eric Davis % Done:

100%

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

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 Feature #6140: REST issues response with issue count limit and offset Closed 2010-08-13
duplicated by Defect #5226: 'can't typecast' in REST API for issues Closed 2010-03-31

Associated revisions

Revision 3631
Added by Eric Davis almost 2 years ago

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

History

Updated by Artem Kulyabin almost 2 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.

Updated by Artem Kulyabin almost 2 years ago

I wrote a script rest.rb:

 1require 'rubygems'
 2require 'active_resource'
 3
 4class Issue < ActiveResource::Base
 5   self.site = 'http://www.redmine.org/'   
 6end
 7
 8issues = Issue.find(:all)
 9puts 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)

Updated by Artem Kulyabin almost 2 years ago

I wrote a script rest2.rb:

 1require 'rubygems'
 2require 'active_resource'
 3
 4class Project < ActiveResource::Base
 5   self.site = 'http://www.redmine.org/'   
 6end
 7
 8projects = Project.find(:all)
 9puts projects.first.name

$ ruby rest2.rb
Redmine

It works!

Updated by Yohann Monnier almost 2 years ago

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

Updated by Eric Davis almost 2 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