Kakuweb Blog Rants and raves. Some interesting stuff, most of it not.

Rails 4.1 upgrade

Rails 4.1 is out and it has some very nice changes, enough to want to make you upgrade immediately, but beware of some issues:


Rails 4.1 and Active Record have a lot of issues with Squeel, and by that I mean that your app will fail to load until you’ve put this into your Gemfile:

gem 'polyamorous', github: 'activerecord-hackery/polyamorous', branch: 'rails-4.1'

Note: You’ll see lots of places where people say that this is enough for Polyamorous to work:

gem 'polyamorous', github: 'activerecord-hackery/polyamorous'

That might have been true at some point, but now you need to add the `branch: ‘rails-4.1’ directive or you’ll get an error in bundle trying to load the gem, something like:

Could not find a valid gem 'polyamorous' (~> 6.0) in any repository

You’ll see an error like this:

undefined method 'graft' for class 'ActiveRecord::Associations::JoinDependency' (NameError)

If the above gem doesn’t clear it, put this in as well:

gem 'activeadmin', github: 'gregbell/active_admin'

The tough thing is that there is very little indication that it is Squeel that is causing the error so it’s hard to track. I love Squeel, I use it on all my Rails and Padrino apps, but that’s the problem with gems that hack other gems, things can get hairy.

Ernie Miller, the guy who created Squeel, has moved all of gems into a new github repository appropriately called activerecord-hackery, you might find some more info there, the bad news is he is not maintaining them anymore, so we’ll have to wait and see if other developers take over the job or we’ll be forced to remove Squeel from all our projects or not upgrade past a certain point.

Beware: right now, even after those changes, you might get errors like wrong number of arguments (3 for 2) for queries that worked fine before with Squeel. If this is the case, you are currently screwed. You can either lock down ActiveRecord to 4.0.4 or remove all traces of Squeel in your code. Neither is an appealing prospect, but of the two I think I would choose to remove Squeel since ActiveRecord is an integral part of Rails.

Update: in fact, that’s just what I had to do, I removed all traces of Squeel from both the applications I had. It took me a couple of days and was a real pain in the arse, but in the end, it was better than relying on a gem that is no longer maintained and one for which there isn’t a clear fix.


Sidekiq has also made a number of changes under the hood in version 3.0.0. We have 2 projects using it and I had to revert to version 2.17.4 because upgrading would require a number of rewrites to our code which I’m not ready for yet, they don’t seem to be huge changes, but after fighting with Sidekiq for a while in our production app (since the errors did not show up in Development) I gave up for the time being and will address them down the line.

The upgrade read me is here

I had 2 errors, the first one was easy to fix:

NameError: uninitialized constant Sidekiq::Stats;

Just put this at the top of the file that calls Sidekiq:

require 'sidekiq/api'

This wasn’t required in version 2.17.4 so it’s a bit weird, but hey that fixed it.

The second error:

ArgumentError - wrong number of arguments (4 for 3):
# for this line
call(worker_instance, msg, queue)

It turns out that:

3rd party gems which use client-side middleware will need to update due to an API change. The Redis connection for a particular job is passed thru the middleware to handle sharding where jobs can be pushed to different redis server instances.

And you’re now supposed to do something like:

call(worker_instance, msg, queue, redis_pool)

Again, not a huge change, but it does require some rewrites, and those are the 2 I found, there’s no guarantee that if I fix those others won’t crop up.

Zeus vs Spring

These are both preloading libraries to make your Rails faster and your life better. Zeus has been around for a while and it’s great, it’s even integrated into Rubymine which is awesome. So what’s the issue? you ask just stick with Zeus. I am but Spring is now integrated into Rails 4.1 by default and it’s always nice to be able to use out of the box solutions, especially ones built by people smarter than you.

If using Rubymine, just make sure to use version 0.13.4-pre2 of Zeus.

gem 'zeus', '0.13.4.pre2'

This last one is not really and issue since it’s only applicable in a development environment but you should be aware of it so you don’t run into problem when upgrading. Pick one of the two and stick with it.

Update: I’ve had several issues with Zeus freezing up on me so I’ve since removed it as well from all my apps, (sigh).


This one might not affect you because it’s a very specific issue:

If you have a table with a column named format and you want to use it in any view (web page) as JSON you are screwed, you will get the following error:

	too few arguments

That’s it, nothing else, no hint as to where this is happening. It turns out it is any time you try to output that table data into a view using JSON. So if you had something like this for example:

	BookFormat.where(format: 'paperback').as_json

Which is perfectly valid and produces something like this:

	BookFormat Load (0.5ms)  SELECT `book_formats`.* FROM `book_formats`  WHERE `book_formats`.`format` = 'paperback'  ORDER BY format
[{"id"=>3, "format"=>"Paperback"}]

You will get the too few arguments error. Which seems to be triggered by Active Record 4.1.1:

	activemodel (4.1.1) lib/active_model/serialization.rb:108:in `block in serializable_hash'

As of May 20 I’ve found no solution to this but to go back to Rails 4.0.4.

Procrastination conclusion

I actually upgraded to 4.1.1 and had most things working but have had to downgrade because of the JSON issue.

Twitter Share this post if you want, or follow me on Twitter if you're into that stuff.
comments powered by Disqus