Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

rails/info causes frameworks that are not already loaded to be (partially?) loaded

#2638

For one particular project, running on Rails 2.3, we do not need ActiveRecord. In config/environment.rb, I have removed the ActiveRecord framework:


Rails::Initializer.run do |config|
  # [ ... ]
  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  config.frameworks -= [ :active_record, :action_mailer ]
end

Unfortunately, a call to Rails::Info causes ActiveRecord to be defined, as you can see from this console session:


mathie@Tullibardine booger (master) $ script/console
Loading development environment (Rails 2.3.2)
Object.con>> Object.const_defined?("ActiveRecord")
=> false
>> Rails::Info
=> About your application's environment
Ruby version              1.8.6 (universal-darwin9.0)
RubyGems version          1.3.3
Rack version              1.0
Rails version             2.3.2
Active Record version     2.3.2
Action Pack version       2.3.2
Active Resource version   2.3.2
Action Mailer version     2.3.2
Active Support version    2.3.2
Application root          /Users/mathie/booger
Environment               development
>> Object.const_defined?("ActiveRecord")
=> true

This causes a problem because some parts of Rails, the generated skeleton application and several plugins check to see if ActiveRecord is defined to test for database support.

The plugin in particular, which both calls Rails::Info and checks for the existence of ActiveRecord in order to enable portions of itself, is New Relic's RPM Agent (which is why I'm about to point those guys at this report too!).

Attached is a patch without tests -- I'll attempt to work on tests just now, but I could always use the help. :-)

Reported by Graeme Mathieson · May 12th, 2009 @ 05:15 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Graeme Mathieson
    Graeme Mathieson

    Got the tests sussed, I think. Attached is a new patch, with tests this time.

    May 12th, 2009 @ 05:39 PM

  2. Frederick Cheung
    Frederick Cheung

    Cool, I've been bitten by this one (also with new relic and a databaseless app). Not someone with a checkout of rails handy, but isn't removing the ActiveRecord constant going to mess up other tests. Perhaps you could put it back afterwards (in an ensure) or mock out the call to const_defined ?

    Also you should rebase down to a single patch.

    May 12th, 2009 @ 08:00 PM

  3. Bill
    Bill

    +1 We also had this problem in NewRelic. As a side effect of collecting Rails information we broke apps that did not include the AR framework.

    The patch looks good to me. I thought maybe you could get the frameworks list from the configuration object and use that as a test instead, but there are probably tradeoffs between both approaches I'm not aware of. Just a thought.

    May 12th, 2009 @ 11:15 PM

  4. Graeme Mathieson
    Graeme Mathieson

    @Frederick: Removing ActiveRecord doesn't seem to be messing up other tests -- I've run the full Rails test suite without issue. Thanks for the squashing tip -- I've attached a new version of the patch which is flattened.

    @Bill Unfortunately, you can't get the frameworks list from the configuration object because it splits out action controller into action view & action pack, which is not what Rails::Info wants to see.

    May 20th, 2009 @ 06:54 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  6. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to stale
    • Importance changed from to

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

    October 9th, 2010 @ 04:14 AM