mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate locking of dirty records
This commit is contained in:
parent
adaa35890b
commit
578f283012
3 changed files with 18 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
* Deprecate locking records with unpersisted changes.
|
||||||
|
|
||||||
|
*Marc Schütz*
|
||||||
|
|
||||||
* Deprecate `ColumnDumper#migration_keys`.
|
* Deprecate `ColumnDumper#migration_keys`.
|
||||||
|
|
||||||
*Ryuta Kamizono*
|
*Ryuta Kamizono*
|
||||||
|
|
|
@ -59,7 +59,16 @@ module ActiveRecord
|
||||||
# or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns
|
# or pass true for "FOR UPDATE" (the default, an exclusive row lock). Returns
|
||||||
# the locked record.
|
# the locked record.
|
||||||
def lock!(lock = true)
|
def lock!(lock = true)
|
||||||
reload(lock: lock) if persisted?
|
if persisted?
|
||||||
|
if changed?
|
||||||
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||||
|
Locking a record with unpersisted changes is deprecated and will raise an
|
||||||
|
exception in Rails 5.2. Use `save` to persist the changes, or `reload` to
|
||||||
|
discard them explicitly.
|
||||||
|
MSG
|
||||||
|
end
|
||||||
|
reload(lock: lock)
|
||||||
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -536,7 +536,10 @@ unless in_memory_db?
|
||||||
Person.transaction do
|
Person.transaction do
|
||||||
person = Person.find 1
|
person = Person.find 1
|
||||||
old, person.first_name = person.first_name, "fooman"
|
old, person.first_name = person.first_name, "fooman"
|
||||||
person.lock!
|
# Locking a dirty record is deprecated
|
||||||
|
assert_deprecated do
|
||||||
|
person.lock!
|
||||||
|
end
|
||||||
assert_equal old, person.first_name
|
assert_equal old, person.first_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue