Skip to content

Commit 233c261

Browse files
committed
Fix spurious versions from touch events with no changes
Previously, `changed_notably?` in `Events::Update` returned `true` for touch events even when `changes_in_latest_version` was empty. This caused spurious version records to be created, particularly when using ActiveStorage, which calls `touch` after attaching blobs. By removing this override, we now delegate to the base class implementation, which only creates versions when there are actual notable changes tracked by Rails' dirty tracking. Fixes #1465
1 parent 0c511ed commit 233c261

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

lib/paper_trail/events/update.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@ def data
3737
merge_metadata_into(data)
3838
end
3939

40-
# If it is a touch event, and changed are empty, it is assumed to be
41-
# implicit `touch` mutation, and will a version is created.
40+
# NOTE: We previously overrode `changed_notably?` here to return `true`
41+
# for touch events even when `changes_in_latest_version` was empty.
42+
# This caused spurious versions when used with ActiveStorage, which
43+
# calls `touch` after attaching blobs without making meaningful changes.
4244
#
43-
# See https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e
45+
# By removing the override, we now delegate to the base class, which
46+
# only creates versions when there are actual notable changes.
4447
#
45-
# @api private
46-
def changed_notably?
47-
if @is_touch && changes_in_latest_version.empty?
48-
true
49-
else
50-
super
51-
end
52-
end
48+
# See https://github.com/paper-trail-gem/paper_trail/issues/1465
49+
# See https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e
5350

5451
private
5552

0 commit comments

Comments
 (0)