Navigation Menu

Skip to content

Commit

Permalink
fixed a 'RecordNotFound' bug when calling 'reload' on a object which …
Browse files Browse the repository at this point in the history
…doesn't met the default_scope conditions, added test [#3166 status:resolved]

The reload method didn't made use of 'with_exclusive_scope' when reloading the object. This lead to a RecordNotFound exception, in case the object doesn't met the default_scope condition (anymore) - which is obviously a bug. This quick fix makes use of with_exclusive_scope in the reload method as well. See test for full example.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Tobias Bielohlawek authored and josevalim committed Feb 26, 2010
1 parent 5695b1b commit b06e5dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -2716,7 +2716,7 @@ def toggle!(attribute)
def reload(options = nil)
clear_aggregation_cache
clear_association_cache
@attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes'))
@attributes.update(self.class.send(:with_exclusive_scope) { self.class.find(self.id, options) }.instance_variable_get('@attributes'))
@attributes_cache = {}
self
end
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1645,6 +1645,12 @@ def test_reload
assert_equal t1.title, t2.title
end

def test_reload_with_exclusive_scope
dev = DeveloperCalledDavid.first
dev.update_attributes!( :name => "NotDavid" )
assert_equal dev, dev.reload
end

def test_define_attr_method_with_value
k = Class.new( ActiveRecord::Base )
k.send(:define_attr_method, :table_name, "foo")
Expand Down

0 comments on commit b06e5dc

Please sign in to comment.