Fixes #6311: Optimistic lock for ActiveRecord does not work as expected