diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-05 04:14:51 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-06 02:03:31 +0900 |
commit | 263f01d93da118dc150c6ac816e70dcf10de2608 (patch) | |
tree | 71442d6fa769733252a0c76ff7da20234c20bd04 /activerecord/lib/active_record/persistence.rb | |
parent | ccac681122db9747fec9512076772bca345e24b9 (diff) | |
download | rails-263f01d93da118dc150c6ac816e70dcf10de2608.tar.gz rails-263f01d93da118dc150c6ac816e70dcf10de2608.tar.bz2 rails-263f01d93da118dc150c6ac816e70dcf10de2608.zip |
Fix that after commit callbacks on update does not triggered when optimistic locking is enabled
This issue is caused by `@_trigger_update_callback` won't be updated due
to `_update_record` in `Locking::Optimistic` doesn't call `super` when
optimistic locking is enabled.
Now optimistic locking concern when updating is supported by
`_update_row` low level API, therefore overriding `_update_record` is no
longer necessary.
Removing the method just fix the issue.
Closes #29096.
Closes #29321.
Closes #30823.
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index ce16587326..d4f4a5887a 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -656,18 +656,11 @@ module ActiveRecord MSG end - time ||= current_time_from_proper_timezone attribute_names = timestamp_attributes_for_update_in_model attribute_names.concat(names) unless attribute_names.empty? - attribute_names.each do |attr_name| - write_attribute(attr_name, time) - clear_attribute_change(attr_name) - end - - affected_rows = _update_row(attribute_names, "touch") - + affected_rows = _touch_row(attribute_names, time) @_trigger_update_callback = affected_rows == 1 else true @@ -688,7 +681,18 @@ module ActiveRecord self.class._delete_record(self.class.primary_key => id_in_database) end - def _update_row(attribute_names, attempted_action) + def _touch_row(attribute_names, time) + time ||= current_time_from_proper_timezone + + attribute_names.each do |attr_name| + write_attribute(attr_name, time) + clear_attribute_change(attr_name) + end + + _update_row(attribute_names, "touch") + end + + def _update_row(attribute_names, attempted_action = "update") self.class._update_record( attributes_with_values(attribute_names), self.class.primary_key => id_in_database @@ -712,7 +716,7 @@ module ActiveRecord affected_rows = 0 @_trigger_update_callback = true else - affected_rows = _update_row(attribute_names, "update") + affected_rows = _update_row(attribute_names) @_trigger_update_callback = affected_rows == 1 end |