You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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: