beerlington/classy_enum — Issue #7: Stack overflow when using classy_enum in the render function
Author: rantav
Created: 2011-11-10 12:48:46+00:00
State: open

Hi, I'm seeing some weird behavior that I can't explain and it seems to be related to classy_enum.
In my model I have:

class Message < ActiveRecord::Base
classy_enum_attr :message_type

And I have the required enums and everything and it seems to work great. (I've used classy_enum in the past, so it's not my first enum. Other times didn't render a model with enums though)

The problem is that when I want to render a @message in the controller I get a stack overflow and sometimes (but not always) a complete server crash with class_enum in the stack

````
Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/classy_enum-1.3.0/lib/classy_enum/class_methods.rb:58:in `const_get': uninitialized constant MessageTypeUser (NameError)
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/classy_enum-1.3.0/lib/classy_enum/class_methods.rb:58:in `build'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/classy_enum-1.3.0/lib/classy_enum/attributes.rb:39:in `block (2 levels) in classy_enum_attr'
from /Users/ran/dev/invi-backend/app/models/message.rb:16:in `to_s'
from /Users/ran/dev/invi-backend/lib/messaging.rb:22:in `block in send'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `call'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `set_deferred_status'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:180:in `fail'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/pusher-0.8.3/lib/pusher/channel.rb:51:in `block in trigger_async'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `call'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `set_deferred_status'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/em/deferrable.rb:180:in `fail'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/em-http-request-0.3.0/lib/em-http/client.rb:310:in `unbind'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:1417:in `event_callback'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.11/lib/thin/backends/base.rb:61:in `start'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.11/lib/thin/server.rb:159:in `start'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.3/lib/rack/handler/thin.rb:14:in `run'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.2.3/lib/rack/server.rb:217:in `start'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands/server.rb:65:in `start'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:30:in `block in '
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:27:in `tap'
from /Users/ran/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:27:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'
````

It's hard to say what exactly is causing this.... but when I remove the classy enum definition in the model the crash doesn't happen.

Does this ring a bell? Have you any idea why is this or how to solve that?

thanks!