Is increment_counter indirectly manipulating lock_version?
I’m testing against concurrency, and I notice lock_version is incrementing. Even though, I am not rescuing from ActiveRecord::StaleObjectError.
http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html says
"Active Records support optimistic locking if the field lock_version is present."
Does this mean increment_counter is triggering a rescue on ActiveRecord::StaleObjectError automatically?
The field lock_version always gets incremented on save when updating a record. Say you have a record with a lock_version of 3. When you save it, it will try doing something as follows:
The ActiveRecord::StaleObjectError gets thrown if the amount of rows updated is equal to zero. Essentially if the rows updated equals zero means that another request already updated the record. For this reason the lock_version always increments.