Tuesday, April 10, 2007

Ruby TypeError (singleton can't be dumped):

This error is very interesting and can possibly waste a lot of time , if you do not know the main reason behind it. I'm sharing this here, so that all those programmers who will possibly run into this issue, Google it for solution and will eventually land on my blog post and hopefully I will save someones day.

Issue is : TypeError (singleton can't be dumped): Now when you are running a Rails app, this will be dumped into your development.log or production.log depending on your application environment.

Full trace will look something like this

/usr/local/lib/ruby/1.8/pstore.rb:348:in `dump'
/usr/local/lib/ruby/1.8/pstore.rb:348:in `dump'
/usr/local/lib/ruby/1.8/pstore.rb:326:in `transaction'
/usr/local/lib/ruby/1.8/cgi/session/pstore.rb:90:in `update'
/usr/local/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close'
/usr/local/lib/ruby/1.8/cgi/session.rb:330:in `close'
.//vendor/rails/actionpack/lib/action_controller/base.rb:1015:in `close_session'

Root cause: In your Ruby/Rails code you are trying to add a singleton class in the session, which is against the compatibility rules. So look for pure singleton class or Modules that's getting added to the rails session.

Solution: Have a class inside the Singelton class which will hold the data that you want to store in session and add that to your session. This will work.


4 comments:

Arthaey said...

Thanks for the post! You saved me some time hunting down this error.

liya said...

Thank you so much!
I come across this problem last night, and did not find a solution to it until this afternoon. You helped a lot!

liya said...

Thanks

Anonymous said...

Nice, thanks for the help.