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

13 views
Skip to first unread message

Kenneth Kalmer

unread,
Nov 24, 2008, 10:05:15 AM11/24/08
to rubyonra...@googlegroups.com
On Mon, Nov 24, 2008 at 2:38 PM, Kenneth Kalmer
<kenneth...@gmail.com> wrote:
> On Fri, Oct 10, 2008 at 9:08 PM, Stephen Bannasch
> <stephen....@deanbrook.org> wrote:
>>>So unless I'm misreading this, it seems we're requiring application.rb
>>>before we try to run the gem installs, but we *haven't* fired the
>>>initializers yet?
>>>
>>>Is it perhaps caused by one of your plugins (rspec f.ex) requiring
>>>application.rb?

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


--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za

Kenneth Kalmer

unread,
Nov 24, 2008, 10:08:46 AM11/24/08
to rubyonra...@googlegroups.com

Kenneth Kalmer

unread,
Nov 24, 2008, 11:00:27 AM11/24/08
to rubyonra...@googlegroups.com
On Mon, Nov 24, 2008 at 5:05 PM, Kenneth Kalmer

<kenneth...@gmail.com> wrote:
> On Mon, Nov 24, 2008 at 2:38 PM, Kenneth Kalmer>
> 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.

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.

Matt Jones

unread,
Nov 24, 2008, 11:33:05 AM11/24/08
to rubyonra...@googlegroups.com
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

On Nov 24, 2008, at 11:00 AM, Kenneth Kalmer wrote:

>
> On Mon, Nov 24, 2008 at 5:05 PM, Kenneth Kalmer
> <kenneth...@gmail.com> wrote:
>> On Mon, Nov 24, 2008 at 2:38 PM, Kenneth Kalmer>
>>

Kenneth Kalmer

unread,
Nov 24, 2008, 2:08:57 PM11/24/08
to rubyonra...@googlegroups.com
On Mon, Nov 24, 2008 at 6:33 PM, Matt Jones <al2...@gmail.com> wrote:
>
> 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.

Matt Jones

unread,
Nov 24, 2008, 4:27:44 PM11/24/08
to rubyonra...@googlegroups.com



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

Matt Jones

unread,
Nov 25, 2008, 12:38:45 AM11/25/08
to rubyonra...@googlegroups.com
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

Kenneth Kalmer

unread,
Nov 26, 2008, 12:46:11 AM11/26/08
to rubyonra...@googlegroups.com
Thanks Matt, applied to the broken app example and it worked
perfectly. Also commented on the ticket.

On Tue, Nov 25, 2008 at 7:38 AM, Matt Jones <al2...@gmail.com> wrote:
> 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

--

Michael Koziarski

unread,
Dec 1, 2008, 2:46:26 PM12/1/08
to rubyonra...@googlegroups.com
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
--
Cheers

Koz

Kenneth Kalmer

unread,
Dec 2, 2008, 1:46:29 AM12/2/08
to rubyonra...@googlegroups.com
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

On Mon, Dec 1, 2008 at 9:46 PM, Michael Koziarski <mic...@koziarski.com> wrote:
>
> 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
>
> On Wed, Nov 26, 2008 at 6:46 AM, Kenneth Kalmer
> <kenneth...@gmail.com> wrote:
> >
> > Thanks Matt, applied to the broken app example and it worked
> > perfectly. Also commented on the ticket.
> >
> > On Tue, Nov 25, 2008 at 7:38 AM, Matt Jones <al2...@gmail.com> wrote:
> >> 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)
> >>

--

Reply all
Reply to author
Forward
0 new messages