Gem clash: activerecord-jdbc-adapter and pg

Posted by Nick Sieger Thu, 28 Jan 2010 15:16:49 GMT

I got a note from a community member about an annoying problem that a few people have run into when installing activerecord-jdbc-adapter (AR-JDBC) into a C Ruby implementation:

NameError: uninitialized constant

Turns out it’s pretty easy to momentarily forget to use jruby -S gem or jgem and just gem install activerecord-jdbc-adapter and suddenly your pg Postgres gems are not working properly. I thought it was worth documenting here in case others run into this problem.

I apologize for the clash. I had to provide a stub pg.rb in AR-JDBC inside of JRuby so that I could get active_record/connection_adapters/postgresql_adapter.rb to load with a database adapter type of postgresql. Because of load path order issues, I couldn’t get AR-JDBC’s code to load before ActiveRecord’s. At the time I was thinking this wouldn’t be a problem because the pg library won’t work on JRuby anyway, right? Wrong.

I can think of a couple options going forward:

  1. Submit a patch to ActiveRecord so that active_record/connection_adapters/postgresql_adapter.rb can load without requiring pg up front and then AR-JDBC won’t have to stub it out.
  2. Display a big fat warning message when AR-JDBC is installed into anything other than JRuby.

Any other thoughts?

Tags ,  | 2 comments


  1. Avatar Charles said about 10 hours later:

    Can’t the gem platform stuff be used to guard against this? If that platform for the AR-JDBC gem is java, shouldn’t MRI ruby refuse to install it?

  2. Avatar Diego E. "Flameeyes" Pettenò said about 13 hours later:

    Right now the gem has no platform (which is probably the same reason why Gentoo is packaging a broken activerecord-jdbc that installs for MRI, for a few more weks ;)) so that might explain it..

    On the other hand, this is one thing that we won’t be hitting ourselves... I actually should remember to package this tomorrow night.

    And by the way, I take the chance to tell you guys that hopefully after FOSDEM I might have pretty nice graphs to show about Gentoo’s support for JRuby: yesterday’s stats shows Ruby 1.9 and JRuby almost tied: 72 vs 70 packages... if headius can get me Duby, I’d have no problem to get the situation reserved, with more gems available for JRuby (now!) than for Ruby 1.9 (in a more distant future, as it’s not unmasked yet).

    Of course, I cannot make Rails to be supported until I can clear racc... and that does not work on 1.4.0, so either I’ll have to wait for 1.5.0 RCs or skip over the tests for now..