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.

reload! doesn't reload

#6447

In 3.0.4, typing reload! in the rails console does not reload the models.

It appears #3822 reload! doesn't reload has regressed. The test case from that bug can be used to repro this issue. Updated 2011-03-01: Sorry, while this issue may be related, it is not the exact same bug as #3822 reload! doesn't reload (I had incorrectly assumed it was), and the test case from that bug will pass. But the issue is real, see test case below:

Here is an updated test case, that fails in 3.0.4:

# app/models/reload_me.rb

class ReloadMe 
  def print_stuff
    print "hello 1"
  end
end
$ rails c
Loading development environment (Rails 3.0.4)
>> blar = ReloadMe.new
=> #<ReloadMe:0x103708650>
>> print
nil=> nil
>> blar.print_stuff
hello 1=> nil

# Now update "hello 1" to be "hello 2" and save. Notice that print_stuff hasn't changed:

>> reload!
Reloading...
=> true
>> blar.print_stuff
hello 1=> nil
>> 

# Now quit and run the test again.  Notice that it it works:

>> quit
$ rails c
Loading development environment (Rails 3.0.4)
>> blar = ReloadMe.new
=> #<ReloadMe:0x103708178>
>> blar.print_stuff
hello 2=> nil

Reported by William Denniss · February 18th, 2011 @ 07:42 AM

State: wontfix
Milestone: none
Assigned to: Jeff Kreeftmeijer Jeff Kreeftmeijer
Importance: Low

Activity

  1. Philipp Steinacher
    Philipp Steinacher
    • Tag set to development environment, console, reload!

    It also doesn't work with Rails 3.0.3 and ruby-1.9.2-p136

    February 19th, 2011 @ 11:27 PM

  2. William Denniss
    William Denniss

    I'm not sure if the version of ruby matters, but for the record:

    $ ruby --version ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

    February 20th, 2011 @ 03:36 AM

  3. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from new to open
    • Importance changed from to Low

    I couldn't reproduce this issue on master or 3.0.4:

    # app/models/user.rb
    
    class User < ActiveRecord::Base
      validates :email, :presence => true
      #validates :name, :presence => true
    end
    
    $ script/rails c
    Loading development environment (Rails 3.1.0.beta)
    irb(main):001:0> u = User.new
    => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
    irb(main):002:0> u.valid?
    => false
    irb(main):003:0> u.errors
    => #<ActiveModel::Errors:0xb7204b50 @base=#<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>, @messages=#<OrderedHash {:email=>["can't be blank"]}>>
    
    # Now, before reloading and without leaving the console, I uncomment the :name validation in the user model.
    
    irb(main):004:0> reload!
    Reloading...
    => true
    irb(main):005:0> u = User.new
    => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
    irb(main):006:0> u.valid?
    => false
    irb(main):007:0> u.errors
    => #<ActiveModel::Errors:0xb6d3ed00 @base=#<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>, @messages=#<OrderedHash {:email=>["can't be blank"], :name=>["can't be blank"]}>>
    

    February 28th, 2011 @ 08:17 PM

  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from new to needs-more-info
    • Assigned user set to Jeff Kreeftmeijer

    Sorry, in my last comment I previously confirmed the issue, but I was doing something wrong. I can't reproduce this issue and I updated my last comment.

    Can anyone else reproduce this? If not, I'll mark this one as invalid. :)

    February 28th, 2011 @ 09:01 PM

  5. William Denniss
    William Denniss

    Hi Jeff,

    Thank you for testing this. I'm sorry for not creating a better bug report, it seems that the test case in #3822 reload! doesn't reload does in fact pass. I had reload! problems in 3.0.4, and incorrectly assumed that #3822 reload! doesn't reload had regressed exactly.

    Please see the updated bug report above for a test case that fails in 3.0.4.

    Thanks again for your time.

    Best Regards,
    Will

    February 28th, 2011 @ 11:49 PM

  6. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from needs-more-info to open

    Thanks Will, I tried to reproduce again:

    # app/models/user.rb
    
    class User < ActiveRecord::Base
      def reloaded?
        false
      end
    end
    
    $ script/rails c
    Loading development environment (Rails 3.1.0.beta)
    irb(main):001:0> u = User.new
    => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
    irb(main):002:0> u.reloaded?
    => false
    irb(main):003:0> reload!
    Reloading...
    => true
    irb(main):004:0> u.reloaded?
    => false
    irb(main):005:0> u = User.new
    => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
    irb(main):006:0> u.reloaded?
    => true
    

    Again, before calling reload!, I changed the model to make User#reloaded? return true. When I call that method on the existing u object, it still returns false after reloading. When I create a new User object, #reload? returns true.

    This confirms your issue on master, I'll re-open the ticket and I'll have a look at it as soon as I can. :)

    March 1st, 2011 @ 06:45 PM

  7. William Denniss
    William Denniss

    Thanks for looking into it Jeff! Glad you were able to repro it.

    March 2nd, 2011 @ 03:03 AM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from open to wontfix

    Hi William,

    After talking to Josh about this, we came to this conclusion:

    The u object doesn't get reloaded because it already existed before the model changed and reload! only takes care of the model in this case. I'm marking this one as wontfix, since reloading instances of objects is not reload!'s job, it simply reloads the environment.

    Thanks for reporting! :)

    March 5th, 2011 @ 12:03 PM