Back to Normal
Sunday, January 13, 2013
I think I have all the bugs fixed.
For anyone who's wondering, this was all caused by a forced upgrade. I don't upgrade the site often, so it's usually running on older versions of the software. But there was a big scary exploit that had been published, so I was forced to upgrade to Rails 2.3.15.
With that upgrade came a bunch of other changes, and it introduced some incompatibilities in pre-existing code. The last one involved the player game history. Probably none of the Second Life players care about this (except that it's been fixed), but I'll document it here for the benefit of any Rails coders confused as to why their named scopes are no longer working.
To generate the player history, I have a named scope which looks something like this:
named_scope :played_by, lambda { |*avs| {
:select => "games.*",
:joins => [:plays => [:avatar] ],
:conditions => {:plays => { :avatars => {:id => avs} } }
}
So I could pull up games played by two player like Games.played_by(mark, john). And that worked fine under Rails 2.3.5. But when I updated to Rails 2.3.15, the same code was giving me ActiveRecord::StatementInvalid.
I didn't get an error message more explicit than that, though. So I had to browse through the Rails code to find out more. It looks like sometime between 2.3.5 and 2.3.15 they changed sanitize_sql_hash so that it no longer accepts nested hases. I don't know why they changed that; it was working fine before. But I had to change my named scope to flatten out the nested hash, like this:
named_scope :played_by, lambda { |*avs| {
:select => "games.*",
:joins => [:plays => [:avatar] ],
:conditions => ["avatars.id in (?)", avs] }
}
And now it works again.