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 # {}
This commit is contained in:
parent
1d7b00d607
commit
e835596ae8
@ -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.
|
||||
|
||||
|
@ -498,7 +498,6 @@ def touch(*names, time: nil)
|
||||
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 @@ def touch(*names, time: nil)
|
||||
changes[locking_column] = increment_lock
|
||||
end
|
||||
|
||||
clear_attribute_changes(changes.keys)
|
||||
result = scope.update_all(changes) == 1
|
||||
|
||||
if !result && locking_enabled?
|
||||
|
@ -181,6 +181,7 @@ def test_touch_existing_lock
|
||||
|
||||
p1.touch
|
||||
assert_equal 1, p1.lock_version
|
||||
assert_not p1.changed?, "Changes should have been cleared"
|
||||
end
|
||||
|
||||
def test_touch_stale_object
|
||||
|
Loading…
Reference in New Issue
Block a user