Fix spurious versions from touch events with no changes#1546
Open
mattmenefee wants to merge 1 commit intopaper-trail-gem:masterfrom
Open
Fix spurious versions from touch events with no changes#1546mattmenefee wants to merge 1 commit intopaper-trail-gem:masterfrom
mattmenefee wants to merge 1 commit intopaper-trail-gem:masterfrom
Conversation
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 paper-trail-gem#1465
mattmenefee
commented
Jan 23, 2026
|
|
||
| # If it is a touch event, and changed are empty, it is assumed to be | ||
| # implicit `touch` mutation, and will a version is created. | ||
| # NOTE: We previously overrode `changed_notably?` here to return `true` |
Author
There was a problem hiding this comment.
It's probably not necessary to retain this comment, so I can remove it after the changes are approved and before this is merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1465 — spurious empty update versions being created when using ActiveStorage.
The Problem
When
has_one_attached(ActiveStorage) callstouchon the parent record after attaching a blob, Paper Trail creates an empty version with no meaningfulobject_changes. This happens becauseEvents::Update#changed_notably?unconditionally returnedtruefor touch events whenchanges_in_latest_versionwas empty.Before this fix:
The Fix
By removing this override, we delegate to the base class implementation which correctly returns
falsewhen there are no notable changes tracked.After this fix:
updated_at→ version IS created (because Rails tracks the change)Breaking Change Notice
This is technically a breaking change for users who rely on the old behavior of always creating versions for touch events. If the maintainers prefer a backward-compatible approach, an alternative would be to add an opt-in configuration option:
The implementation for the opt-in approach would be:
Happy to implement this alternative if preferred.
Test Plan
touchto create versions may need updating if Rails doesn't track theupdated_atchangeRelated
Contribution Checklist
master(if not - rebase it).code introduces user-observable changes.
and description in grammatically correct, complete sentences.
Notes on unchecked items