nesquena/rabl — Issue #148: RABLS hates hashes of Objects (stack level too deep after upgrading to 0.5.3 from 0.2.8)
Author: bkimble
Created: 2012-01-19 22:08:44+00:00
State: open

First off, thanks for writing this gem. I love it and hope you continue to find the motivation to maintain it!

In the case where we had a hash of objects (or a hash of an array of objects) and called child on it, it would work as expected in 0.2.8, but that seems to no longer be the case in 0.5.3.

In controller:

@test = {"one" => [Object.new,Object.new,Object.new,Object.new], "two" => [Object.new,Object.new,Object.new,Object.new], "three" => [Object.new,Object.new,Object.new,Object.new]}
end

In view:

object false
child @test => :test do
node :foo do |s,v|
s
end
node :count do |s,v|
v.count
end
end

returns:

{
"test": [{
"foo": "three",
"count": 4
},
{
"foo": "two",
"count": 4
},
{
"foo": "one",
"count": 4
}]
}

After upgrading to 0.5.3, it now returns:

stack level too deep

Extracted source (around line #1):

1: object false
2: child @test => :test do
3: node :foo do |s,v|
4: s

Here is the top of the application trace where it looks like it may get caught in a loop:

activesupport (3.1.3) lib/active_support/core_ext/string/access.rb:41:in `first'
rabl (0.5.3) lib/rabl/helpers.rb:21:in `data_name'
rabl (0.5.3) lib/rabl/helpers.rb:21:in `data_name'
rabl (0.5.3) lib/rabl/builder.rb:40:in `to_hash'
rabl (0.5.3) lib/rabl/engine.rb:43:in `to_hash'
rabl (0.5.3) lib/rabl/engine.rb:25:in `map'
rabl (0.5.3) lib/rabl/engine.rb:43:in `each'
rabl (0.5.3) lib/rabl/engine.rb:43:in `map'
rabl (0.5.3) lib/rabl/engine.rb:43:in `to_hash'
rabl (0.5.3) lib/rabl/engine.rb:28:in `send'
rabl (0.5.3) lib/rabl/engine.rb:28:in `render'
rabl (0.5.3) lib/rabl/helpers.rb:48:in `object_to_hash'
rabl (0.5.3) lib/rabl/builder.rb:84:in `child'
rabl (0.5.3) lib/rabl/builder.rb:33:in `to_hash'
rabl (0.5.3) lib/rabl/builder.rb:32:in `each'
rabl (0.5.3) lib/rabl/builder.rb:32:in `to_hash'
rabl (0.5.3) lib/rabl/engine.rb:37:in `to_hash'
rabl (0.5.3) lib/rabl/engine.rb:53:in `to_json'
rabl (0.5.3) lib/rabl/engine.rb:28:in `send'
rabl (0.5.3) lib/rabl/engine.rb:28:in `render'
actionpack (3.1.3) lib/action_view/template.rb:171:in `send'
actionpack (3.1.3) lib/action_view/template.rb:171:in `render'
activesupport (3.1.3) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.3) lib/action_view/template.rb:169:in `render'

Did something change along the way to break this? What is the proper way of going through a hash of objects, or a hash of an array of objects? This issue may be related to the one that @minter opened at https://github.com/nesquena/rabl/issues/146 . Thanks in advance for any insight you can provide!