diff options
author | Jakob Skjerning <jakob@mentalized.net> | 2016-09-14 17:07:15 +0200 |
---|---|---|
committer | Jakob Skjerning <jakob@mentalized.net> | 2016-09-14 17:37:04 +0200 |
commit | e835596ae882e748e452e52131c2a4244336660b (patch) | |
tree | 766ab99a4c2f407fc3c7c8a19f13fe4cd724f75a /activerecord | |
parent | 1d7b00d6072e4749e90fb4bc8307dc06b052848d (diff) | |
download | rails-e835596ae882e748e452e52131c2a4244336660b.tar.gz rails-e835596ae882e748e452e52131c2a4244336660b.tar.bz2 rails-e835596ae882e748e452e52131c2a4244336660b.zip |
Clear attribute changes after handling locking
Without this the changes to the lock version column will stick around
even after `touch` returns.
Before:
model.touch
model.changes
# => {"lock_version"=>[0, "1"]}
After:
model.touch
model.changes
# {}
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 7 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/locking_test.rb | 1 |
3 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index bca719cb2f..786420f51e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Calling `touch` on a model using optimistic locking will now leave the model + in a non-dirty state with no attribute changes. + + Fixes #26496. + + *Jakob Skjerning* + * Using a mysql2 connection after it fails to reconnect will now have an error message saying the connection is closed rather than an undefined method error message. diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index a04ef2e263..978fb27cab 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -498,7 +498,6 @@ module ActiveRecord changes[column] = write_attribute(column, time) end - clear_attribute_changes(changes.keys) primary_key = self.class.primary_key scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key)) @@ -508,6 +507,7 @@ module ActiveRecord changes[locking_column] = increment_lock end + clear_attribute_changes(changes.keys) result = scope.update_all(changes) == 1 if !result && locking_enabled? diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index 5c55584ff7..13b6f6daaf 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -181,6 +181,7 @@ class OptimisticLockingTest < ActiveRecord::TestCase p1.touch assert_equal 1, p1.lock_version + assert_not p1.changed?, "Changes should have been cleared" end def test_touch_stale_object |