can't run: rake gems:install if application.rb depends on initializers [REPRODUCED]

No it is not. I managed to get the issue reproduced in a very tiny
application using Rails 2.2.2.

The code is available at
git://github.com/kennethkalmer/rails-broken-gems-example.git and shows
exactly how to simulate the breakage mentioned by Steven. Please
review the README file
(http://github.com/kennethkalmer/rails-broken-gems-example/tree/master)
for a complete breakdown of the issue and how to fix it.

In a nutshell, it boils down to the one-line patch below:

--- a/vendor/rails/railties/lib/initializer.rb
+++ b/vendor/rails/railties/lib/initializer.rb
@@ -284,7 +284,7 @@ module Rails
     def check_gem_dependencies
       unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
       if unloaded_gems.size > 0
- @gems_dependencies_loaded = false
+ @gems_dependencies_loaded = false || $rails_gem_installer
         # don't print if the gems rake tasks are being run
         unless $rails_gem_installer
           abort <<-end_error

Any feedback would be appreciated, including pointers to the correct
Lighthouse tickets for making my case.

Best

Original thread at
http://groups.google.com/group/rubyonrails-core/browse_thread/thread/8409d0d8f006f8f5,
my apologies.

Seems I was in a too big a hurry, this does solve the initial issue
but creates a new one upon running 'rake gems', which now complains
about the gem specifications...

I'll investigate and report my findings.

Best

The problem with loading initializers is that they are likely to try to use the configured gems
(ie, to set options, etc.). So loading them is going to cause more problems than it solves.
FWIW, this problem goes away on edge - http://github.com/rails/rails/commit/a026b4c983681b71d876ea37958c3e5bc605acac
avoids preloading ApplicationController, and thus solves this. (I tested it...)

What's the error about the specifications?

--Matt

The problem with loading initializers is that they are likely to try
to use the configured gems
(ie, to set options, etc.). So loading them is going to cause more
problems than it solves.

This is a chicken and egg scenario, no wonder it is such hot topic.
Good point, didn't consider that since I was hunting the bug in
extreme anger.

FWIW, this problem goes away on edge - http://github.com/rails/rails/commit/a026b4c983681b71d876ea37958c3e5bc605acac
avoids preloading ApplicationController, and thus solves this. (I
tested it...)

Nice, will have a look too.

What's the error about the specifications?

$ rake gems
(in /home/kenneth/work/tmp/rails-broken-gems-example)
- [I] settingslogic
rake aborted!
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.dependencies

vendor/rails/railties/lib/rails/gem_dependency.rb:77:in `dependencies'

all_dependencies = specification.dependencies.map do |dependency|
  GemDependency.new(dependency.name, :requirement =>
dependency.version_requirements)
end

Thanks for digging into this with me.

Best

Nice, will have a look too.

What’s the error about the specifications?

$ rake gems
(in /home/kenneth/work/tmp/rails-broken-gems-example)

  • [I] settingslogic
    rake aborted!
    You have a nil object when you didn’t expect it!
    The error occurred while evaluating nil.dependencies

vendor/rails/railties/lib/rails/gem_dependency.rb:77:in `dependencies’

all_dependencies = specification.dependencies.map do |dependency|
GemDependency.new(dependency.name, :requirement =>
dependency.version_requirements)
end

Oops - this bit actually is a bug. It’s a short patch; I’ll put it up on Lighthouse tonight with

a test case.

–Matt Jones

Patch is on lighthouse and includes a test for this case:
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1464

(patch against 2-2-stable branch)

–Matt Jones

Thanks Matt, applied to the broken app example and it worked
perfectly. Also commented on the ticket.

Applied to master and 2-2 stable. Are there any other pending gems
changes we should investigate before we cut a 2.2 point release to
address

Not that I'm currently aware off. I'll continue trying to find some
fringe cases and in those cases address the issue more clearly than I
did this one (and without anger).

Thanks everyone