diff --git a/CHANGELOG b/CHANGELOG index 0569c9aac..27db1be9e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ === master +* Make optimistic_locking plugin not keep lock column in changed_columns after updating instance (jeremyevans) (#2196) + * Have defaults_setter plugin pass model instance to default_values callable if it has arity 1 (pedrocarmona) (#2195) * Support string_agg extension on SQLite 3.44+ (segiddins) (#2191) diff --git a/lib/sequel/plugins/optimistic_locking.rb b/lib/sequel/plugins/optimistic_locking.rb index 8ccc04be3..790cd3d6c 100644 --- a/lib/sequel/plugins/optimistic_locking.rb +++ b/lib/sequel/plugins/optimistic_locking.rb @@ -45,6 +45,8 @@ def _update_columns(columns) columns[lc] = lcv + 1 super set_column_value("#{lc}=", lcv + 1) + changed_columns.delete(lc) + nil end end end diff --git a/spec/extensions/optimistic_locking_spec.rb b/spec/extensions/optimistic_locking_spec.rb index 7ca9de920..b34f211ba 100644 --- a/spec/extensions/optimistic_locking_spec.rb +++ b/spec/extensions/optimistic_locking_spec.rb @@ -124,4 +124,11 @@ proc{p1.save_changes}.must_raise(RuntimeError) p1.lock_version.must_equal lv end + + it "should not marked the lock column changed after saving" do + p1 = @c[1] + p1.modified! + p1.save_changes + p1.changed_columns.must_be_empty + end end