Does rails ever automatically bring in a gem?

I've tried to answer this myself, with my friends and on the rails list. No joy,

I got to thinking that something subtle changed between rails 2.3.x and 2.3.5 which I don't know about.

I am troubleshooting a weird scenario where a rails app works on one machine's environment but fails on another machine. The error is: "uninitialized constant REXML::Document"

It is easily solved by adding require 'rexml/document' to the appropriate source file. But the mystery is, why is that line not ALWAYS needed?

So my question is, is there a mechanism similar to dependencies.rb that under certain circumstances implicitly would do the 'require'?

I've tried to answer this myself, with my friends and on the rails list. No joy,

I got to thinking that something subtle changed between rails 2.3.x and 2.3.5 which I don't know about.

I am troubleshooting a weird scenario where a rails app works on one machine's environment but fails on another machine. The error is: "uninitialized constant REXML::Document"

It is easily solved by adding require 'rexml/document' to the appropriate source file. But the mystery is, why is that line not ALWAYS needed?

I got to thinking that something subtle changed between rails 2.3.x and 2.3.5 which I don't know about.

What was the other version you're upgrading from?

I am troubleshooting a weird scenario where a rails app works on one machine's environment but fails on another machine. The error is: "uninitialized constant REXML::Document"

Could you paste a full stacktrace into gist.github.com so we can see where it's happening

It is easily solved by adding require 'rexml/document' to the appropriate source file. But the mystery is, why is that line not ALWAYS needed?

This is a bug, at a guess it's pulling in the rexml expansion fix when you're using an alternative XmlMini backend.

> I got to thinking that something subtle changed between rails 2.3.x > and 2.3.5 which I don't know about.

What was the other version you're upgrading from?

Koz,

Actually I wasn't upgrading; as far as I can 'tell' both systems are running the same version; but I was working a hypothesis.

> I am troubleshooting a weird scenario where a rails app works on one > machine's environment but fails on another machine. The error is: > "uninitialized constant REXML::Document"

Could you paste a full stacktrace into gist.github.com so we can see where it's happening

Thanks,

Pito

Probably doesn’t affect your issue, but is definitely on-topic:

There is a known case that Rails (ActiveSupport) loads Hpricot unconditionally:

https://rails.lighthouseapp.com/projects/8994/tickets/2469-latest-hpricot-installed-always-loaded-on-rake-tasks-despite-configgem-version

Two troubleshooting steps:

Can you paste the gem list --all on both machines?

Can you puts caller in rexml/document on the machine that’s pulling it in and paste it here?

Thanks!

Yehuda Katz Developer | Engine Yard (ph) 718.877.1325

Gems on the machine where the gem is not automatically pulled in:

Two troubleshooting steps: Can you paste the gem list --all on both machines?

actionmailer (2.3.5, 2.3.4, 2.2.2) actionpack (2.3.5, 2.3.4, 2.2.2) activerecord (2.3.5, 2.3.4, 2.2.2) activeresource (2.3.5, 2.3.4, 2.2.2) activesupport (2.3.5, 2.3.4) authlogic (2.1.3) cgi_multipart_eof_fix (2.5.0) configuration (1.1.0) daemons (1.0.10) fastercsv (1.5.0) fastri (0.3.1.1) fastthread (1.0.1) flexmock (0.8.6) gem_plugin (0.2.3) gemcutter (0.2.0) heroku (1.3.0) hpricot (0.8.2) json (1.2.0) json_pure (1.2.0) launchy (0.3.3) libxml-ruby (1.1.3) linecache (0.43) macaddr (1.0.0) mongrel (1.1.5) net-scp (1.0.2) net-ssh (2.0.16) prawn (0.7.1, 0.6.3) prawn-core (0.7.1, 0.6.3) prawn-format (0.2.3) prawn-layout (0.7.1, 0.3.2) prawn-security (0.7.1, 0.1.1) rack (1.0.1) rails (2.3.5, 2.3.4, 2.2.2) rails_best_practices (0.3.16) rake (0.8.7, 0.8.4) rcov (0.8.1.2.0) rest-client (1.0.3) rio (0.4.2) rmagick (2.11.1) ruby-debug-base (0.10.3) ruby-debug-ide (0.4.5) ruby-prof (0.7.3) ruby2ruby (1.2.4) ruby_parser (2.0.4) rubygems-update (1.3.5) sexp_processor (3.0.3) sqlite3-ruby (1.2.1) thoughtbot-factory_girl (1.2.2) thoughtbot-shoulda (2.10.2) uuid (2.0.2) wirble (0.1.3) wxruby (1.9.3) xmpp4r (0.5) yumlcmd (0.0.3)

List of gems on the machine where it IS being pulled in automatically:

actionmailer (2.3.5, 2.2.2, 1.3.6) actionpack (2.3.5, 2.2.2, 1.13.6) actionwebservice (1.2.6) activerecord (2.3.5, 2.2.2, 1.15.6) activeresource (2.3.5, 2.2.2) activesupport (2.3.5, 2.2.2, 1.4.4) acts_as_ferret (0.4.4, 0.4.3) Ascii85 (1.0.0, 0.9.0) authlogic (2.1.3) capistrano (2.5.11, 2.5.10, 2.5.2) cgi_multipart_eof_fix (2.5.0) columnize (0.3.1) daemons (1.0.10) dnssd (1.3.1, 0.6.0) fastthread (1.0.7, 1.0.1) fcgi (0.8.8, 0.8.7) ferret (0.11.6) gem_plugin (0.2.3) highline (1.5.1, 1.5.0) hpricot (0.8.2, 0.6.164) libxml-ruby (1.1.3, 1.1.2) linecache (0.43) mislav-will_paginate (2.3.11) mocha (0.9.8) mongrel (1.1.5) needle (1.3.0) net-scp (1.0.2, 1.0.1) net-sftp (2.0.4, 2.0.1, 1.1.1) net-ssh (2.0.17, 2.0.4, 1.1.4) net-ssh-gateway (1.0.1, 1.0.0) nifty-generators (0.3.0) pdf-reader (0.8.2, 0.8.1) prawn (0.7.1, 0.6.3) prawn-core (0.7.1, 0.6.3) prawn-format (0.2.3) prawn-layout (0.7.1, 0.3.2) prawn-security (0.7.1, 0.1.1) rack (1.1.0, 1.0.1) rails (2.3.5, 2.2.2, 1.2.6) rake (0.8.7, 0.8.3) rb-appscript (0.5.3) rdoc (2.4.3) RedCloth (4.2.2, 4.1.1) ruby-debug-base (0.10.3) ruby-debug-ide (0.4.9) ruby-openid (2.1.7, 2.1.2) ruby-yadis (0.3.4) rubygems-update (1.3.5) rubynode (0.1.5) sqlite3-ruby (1.2.5, 1.2.4) termios (0.9.4) test-spec (0.10.0) xmpp4r (0.5, 0.4)

In order to properly troubleshoot, I need step 2, but try gem cleanup on both machines and see if it fixes it.

Yehuda Katz Developer | Engine Yard (ph) 718.877.1325

Yehuda,

Here are a couple of traces... I don't understand them exactly but say what, on the 'working' environment, it looks like Rails extends Ruby's rexml as part of its core suite, and all of rexml gets loaded automatically when the server starts. Also see the next quote in case it's useful of the include path...

Here's what the stack looks like when rexml is included:

script/server

/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/rexml.rb:8 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext.rb:8 /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext.rb:8:in `each' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext.rb:8 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support.rb:55 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' /Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:1 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' script/server:3 => Booting Mongrel => Rails 2.3.5 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server

If you are curious, this is my include path on startup: ["/Library/Ruby/Gems/1.8/gems/prawn-core-0.7.1/lib/prawn/../../vendor/ttfunk/lib", "/Library/Ruby/Gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/vendor/tmail-1.2.3", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/vendor/i18n-0.1.3/lib", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/vendor/tzinfo-0.3.12", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/vendor/memcache-client-1.7.4", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/vendor/builder-2.1.2", "/Users/atotic/rr/ElectionManager/app/controllers/", "/Users/atotic/rr/ElectionManager/app", "/Users/atotic/rr/ElectionManager/app/models", "/Users/atotic/rr/ElectionManager/app/controllers", "/Users/atotic/rr/ElectionManager/app/helpers", "/Users/atotic/rr/ElectionManager/lib", "/Library/Ruby/Gems/1.8/gems/prawn-0.7.1/lib", "/Library/Ruby/Gems/1.8/gems/authlogic-2.1.3/lib", "/Users/atotic/rr/ElectionManager/vendor", "/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/../builtin/rails_info/", "/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin", "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/rack-1.0.1/bin", "/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib", "/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/actionmailer-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/actionmailer-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/activeresource-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/activeresource-2.3.5/lib", "/Library/Ruby/Gems/1.8/gems/rails-2.3.5/bin", "/Library/Ruby/Gems/1.8/gems/authlogic-2.1.3/bin", "/Library/Ruby/Gems/1.8/gems/prawn-core-0.7.1/bin", "/Library/Ruby/Gems/1.8/gems/prawn-core-0.7.1/lib", "/Library/Ruby/Gems/1.8/gems/prawn-layout-0.7.1/bin", "/Library/Ruby/Gems/1.8/gems/prawn-layout-0.7.1/lib", "/Library/Ruby/Gems/1.8/gems/prawn-security-0.7.1/bin", "/Library/Ruby/Gems/1.8/gems/prawn-security-0.7.1/lib", "/Library/Ruby/Gems/1.8/gems/prawn-0.7.1/bin", "/Library/Ruby/Gems/1.8/gems/hpricot-0.8.2/bin", "/Library/Ruby/Gems/1.8/gems/hpricot-0.8.2/lib", "/Library/Ruby/Gems/1.8/gems/mocha-0.9.8/bin", "/Library/Ruby/Gems/1.8/gems/mocha-0.9.8/lib", "/Library/Ruby/Site/1.8", "/Library/Ruby/Site/1.8/powerpc-darwin10.0", "/Library/Ruby/Site/1.8/universal-darwin10.0", "/Library/Ruby/Site", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin10.0", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin10.0", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0", "."]

Tell me what you found out.

The trick here is that rexml/document is only required inside this conditional (in core_ext/rexml.rb):

unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2"

So I'm guessing the working machine has an earlier patchlevel of Ruby that triggers the fix, and the not-working one obviously has a later version that doesn't.

The results of 'ruby -v' on both should show a difference...

--Matt Jones

The trick here is that rexml/document is only required inside this conditional (in core_ext/rexml.rb):

unless (defined?(REXML::VERSION) ? REXML::VERSION : REXML::Version) > "3.1.7.2"

So I'm guessing the working machine has an earlier patchlevel of Ruby that triggers the fix, and the not-working one obviously has a later version that doesn't.

Working machine: ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] Not working machine: ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]

Indeed. So, is it a bug in Rails, or a bug in Ruby, or a bug in my brain?

Thanks!!

- Pito

I’m guessing the bug was fixed between p72 and p174. As a result, rexml is being pulled in by Rails to apply the security patch on p72, but no on p174. So no bug at all.

In general, if you want rexml, you should require it yourself (as opposed to relying on it being a dependency of some other library…)

Yehuda Katz Developer | Engine Yard (ph) 718.877.1325

Thanks all for the insights.

- Pito

That's right, it was present in the first patch levels and fixed later. That's why the patch is still in AS for Rails 3 (albeit it requires 1.8.7).