Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3558 (closed defect: wontfix)

Opened 3 years ago

Last modified 1 year ago

Model reloading fails after first load in development mode

Reported by: robbyrussell Assigned to: David
Priority: high Milestone: 1.2.4
Component: ActiveSupport Version:
Severity: major Keywords:
Cc: bitsweat, Ulysses

Description

Okay, this is really odd. I encountered the same issue yesterday.

irb(#<ContactTypesController:0x262e570>):009:0> ContactType
=> ContactType
irb(#<ContactTypesController:0x262e570>):010:0> ContactType.methods.include? 'count'
=> true
irb(#<ContactTypesController:0x262e570>):011:0> ContactType.superclass
=> ActiveRecord::Base
irb(#<ContactTypesController:0x262e570>):012:0> 
Server exited. Closing connection...

Reload page...

No connection to breakpoint service at druby://localhost:42531 (DRb::DRbConnError)
Tries to connect will be made every 2 seconds...
Executing break point at ./script/../config/../app/controllers/contact_types_controller.rb:6 in `index'
irb(#<ContactTypesController:0x277b93c>):001:0> ContactType
=> ContactType
irb(#<ContactTypesController:0x277b93c>):002:0> ContactType.superclass
=> Object
irb(#<ContactTypesController:0x277b93c>):003:0> ContactType.methods.include? 'count'
=> false

This does not happen in production mode... just development.

Change History

07/23/06 20:09:34 changed by bgoethals@twodecode.com

  • priority changed from normal to high.
  • version deleted.
  • severity changed from normal to major.

Idd, we have found several issuses that probably have the same "bug" in development mod. I was going to post these as new Ticket, but then I saw this one.

In development mode several things seem to become imposible.

  • Observers
  • Using Classes defined in Liberary, that are loaded in the enviroment.rb file (Structs for WebServices)
  • Other?

This is - we think - because of the Class (models) are reloaded, but references to other Classes, Models, files are lost. Actually we are quite sure, cause if you remove the "config.cache_classes = false" line in config/environments/development.rb"; the problems are gone.

My suggestion untill this is fixed is setting config.cache_classes = true in your development.rb file.

11/09/06 08:40:58 changed by bitsweat

  • cc set to bitsweat.
  • component changed from ActiveRecord to ActiveSupport.
  • milestone set to 1.x.

Are you still seeing this behavior on edge? Outside of breakpoint?

11/09/06 08:41:46 changed by bitsweat

  • cc changed from bitsweat to bitsweat, Ulysses.
  • milestone changed from 1.x to 1.2.

04/15/07 20:57:21 changed by labrat

This is happening to me now that I'm using has_many_polymorph's acts_as_double_polymorphic_join as follows:

class Friendship < ActiveRecord::Base

belongs_to :befriender, :polymorphic => true belongs_to :befriended, :polymorphic => true

acts_as_double_polymorphic_join :befrienders => [:users],

:befriendeds => [:users]

end

This results in befriender and befriendeds being unloaded on a browser refresh.

Here's the error output:

NoMethodError (undefined method `befriendeds' for #<User:0x31bbc20>):

.//vendor/rails/activerecord/lib/active_record/base.rb:1860:in `method_missing' .//app/controllers/friends_controller.rb:18:in `list' .//app/controllers/friends_controller.rb:7:in `index' .//vendor/rails/actionpack/lib/action_controller/base.rb:1095:in `send' .//vendor/rails/actionpack/lib/action_controller/base.rb:1095:in `perform_action_without_filters' .//vendor/rails/actionpack/lib/action_controller/filters.rb:632:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:634:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call' .//vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call' .//vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call' .//vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter' .//app/controllers/application.rb:47:in `set_timezone' .//vendor/rails/actionpack/lib/action_controller/filters.rb:456:in `send' .//vendor/rails/actionpack/lib/action_controller/filters.rb:456:in `call' .//vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter' .//vendor/rails/actionpack/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark' .//vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' .//vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue' .//vendor/rails/actionpack/lib/action_controller/rescue.rb:83:in `perform_action' .//vendor/rails/actionpack/lib/action_controller/base.rb:430:in `send' .//vendor/rails/actionpack/lib/action_controller/base.rb:430:in `process_without_filters' .//vendor/rails/actionpack/lib/action_controller/filters.rb:624:in `process_without_session_management_support' .//vendor/rails/actionpack/lib/action_controller/session_management.rb:114:in `process' .//vendor/rails/actionpack/lib/action_controller/base.rb:330:in `process' .//vendor/rails/railties/lib/dispatcher.rb:41:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 .//vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:488:in `load' .//vendor/rails/railties/lib/commands/servers/mongrel.rb:60 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in' .//vendor/rails/activesupport/lib/active_support/dependencies.rb:495:in `require' .//vendor/rails/railties/lib/commands/server.rb:39 script/server:3:in `require' script/server:3

the only remedy is to set "config.cache_classes = true"

This is beyond my grasp but I'm curious as to why dependencies.rb define load & require are copy & paste twins (around line 487):

def load(file, *extras)

Dependencies.new_constants_in(Object) { super(file, *extras) }

rescue Exception => exception # errors from loading file

exception.blame_file! file raise

end

def require(file, *extras)

Dependencies.new_constants_in(Object) { super(file, *extras) }

rescue Exception => exception # errors from required file

exception.blame_file! file raise

end

And in Railties initializer.rb we have:

def initialize_dependency_mechanism

Dependencies.mechanism = configuration.cache_classes ? :require : :load

end

06/25/07 21:48:21 changed by evan

  • status changed from new to closed.
  • resolution set to wontfix.

The issue with has_many_polymorphs is not related to this bug.

I am aware that similar bugs can still happen, but it should probably be opened as a new ticket (hopefully with a repeatable testcase... some how) since all of the Rails internals have changed in the meantime.