This project is archived and is in readonly mode.

#6447 ✓wontfix
William Denniss

reload! doesn't reload

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

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

It appears #3822 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 (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

Comments and changes to this ticket

  • Philipp Steinacher

    Philipp Steinacher February 19th, 2011 @ 11:27 PM

    • Tag set to development environment, console, reload!

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

  • William Denniss

    William Denniss February 20th, 2011 @ 03:36 AM

    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]

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer February 28th, 2011 @ 08:17 PM

    • 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"]}>>
    
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer February 28th, 2011 @ 09:01 PM

    • 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. :)

  • William Denniss

    William Denniss February 28th, 2011 @ 11:49 PM

    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 does in fact pass. I had reload! problems in 3.0.4, and incorrectly assumed that #3822 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

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer March 1st, 2011 @ 06:45 PM

    • 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. :)

  • William Denniss

    William Denniss March 2nd, 2011 @ 03:03 AM

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

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer March 5th, 2011 @ 12:03 PM

    • 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! :)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages