Skip to content

Commit 16df732

Browse files
committed
Revert "Merge pull request rails#19783 from vngrs/raise_error_on_touch_if_object_is_stale"
This reverts commit 3036490. Reason: It brokes some tests with has_one association what can cause an regression
1 parent 57565f3 commit 16df732

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

activerecord/lib/active_record/persistence.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -466,23 +466,11 @@ def touch(*names)
466466
changes[column] = write_attribute(column, current_time)
467467
end
468468

469+
changes[self.class.locking_column] = increment_lock if locking_enabled?
470+
469471
clear_attribute_changes(changes.keys)
470472
primary_key = self.class.primary_key
471-
scope = self.class.unscoped.where(primary_key => _read_attribute(primary_key))
472-
473-
if locking_enabled?
474-
locking_column = self.class.locking_column
475-
scope = scope.where(locking_column => _read_attribute(locking_column))
476-
changes[locking_column] = increment_lock
477-
end
478-
479-
result = scope.update_all(changes) == 1
480-
481-
if !result && locking_enabled?
482-
raise ActiveRecord::StaleObjectError.new(self, "touch")
483-
end
484-
485-
result
473+
self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
486474
else
487475
true
488476
end

activerecord/test/cases/locking_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,6 @@ def test_touch_existing_lock
177177
assert_equal 1, p1.lock_version
178178
end
179179

180-
def test_touch_stale_object
181-
person = Person.create!(first_name: 'Mehmet Emin')
182-
stale_person = Person.find(person.id)
183-
person.update_attribute(:gender, 'M')
184-
185-
assert_raises(ActiveRecord::StaleObjectError) do
186-
stale_person.touch
187-
end
188-
end
189-
190180
def test_lock_column_name_existing
191181
t1 = LegacyThing.find(1)
192182
t2 = LegacyThing.find(1)

0 commit comments

Comments
 (0)