From d6f4faa4b26d2f8febdc65a1f300d31fadc37505 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Mon, 29 Jul 2024 11:01:27 -0700 Subject: [PATCH] Make optimistic_locking plugin not keep lock column in changed_columns after updating instance --- CHANGELOG | 2 ++ lib/sequel/plugins/optimistic_locking.rb | 2 ++ spec/extensions/optimistic_locking_spec.rb | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 0569c9aac9..27db1be9e5 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 8ccc04be3b..790cd3d6c3 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 7ca9de920b..b34f211ba4 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