-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty "update" versions when using active storage #1465
Comments
Note that this issue doesn't happen if you turn off version creation on As in: class User < ApplicationRecord
has_paper_trail on: %i[create update destroy]
end |
I'm facing the same issue |
@mochetts typo should be |
This issue has been automatically marked as stale due to inactivity. |
I am also seeing this issue when using Action Text, i.e. a model with has_rich_text :foobar and has_paper_trail |
This issue has been automatically marked as stale due to inactivity. |
Not stale. |
Thank you for your contribution!
Due to limited volunteers, issues that do not follow these instructions will be
closed without comment.
Check the following boxes:
paper_trail
gemDue to limited volunteers, we cannot answer usage questions. Please ask such
questions on StackOverflow.
I couldn't use the script template as I needs Rails to reproduce the bug. But I'm attaching a demo repo in which the bug reproduces.
Checkout this repository:
https://github.com/mochetts/paper-trail-active-storage-bug
Run
rails db:migrate
to run migrations.Run
rake
to run minitests.See that the test fails:
Some analysis I've been doing:
It seems that Rails touches records when storing a
has_one_attached
relationship as per this bug report and its consequent fix.This means that every time a new record is created with an associated attachment, it touches the model multiple times, generating multiple "update" versions for it with
nil
"object_changes". This seems to happen because the touch is occurring on creation, when there's no "updated_at" to touch.Now the real question is if this is a Rails bug or a Papertrail bug, as it only happens under this scenario. Worthy to mention that rails forbids you from performing a
touch
on a new record, but under these circumstances it seems to be doing by itself.I would suggest skipping the insertion of "update" versions when
object_changes = nil
, as these become noise in the versions history of the model.I can send a PR for this, but I'd need confirmation that this is the right path.
The text was updated successfully, but these errors were encountered: