This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Weird session bug
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Yesterday I spent about an hour tracking down this bizarro bug I had seen occasionally in the logs but hadn't figured out:
TypeError (singleton can't be dumped):
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action_controller/session/active_record_store.rb:82:in `dump'
I was finally able to reproduce this consistently. It seemed if a new user tried to log in for the first time they would smack into this bug. But, if I created their user account in advance then all was well. I eventually came to the conclusion that it was the session handling.
Further inspection revealed the culprit. I had previously implemented a feature request that new users from a specific group be given automatic visitor access (instead of simply being denied access). So, the basic code structure looked something like this:
user = User.find(uid)
if !user and login_group == 'some_special_group'
user = User.create(visitor)
else
# Deny access
end
session[:user] = user
Except, it turns out that while a user object returned by User.find is compatible with the session object, one returned by User.create was not compatible with the session store, and I'd get the mysterious "Singleton can't be dumped" error.
Why? Couldn't tell you. My workaround is to run User.find again for new users and assign that user object to the session.