Skip to content
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

Open
3 tasks done
mochetts opened this issue Mar 13, 2024 · 7 comments
Open
3 tasks done

Empty "update" versions when using active storage #1465

mochetts opened this issue Mar 13, 2024 · 7 comments

Comments

@mochetts
Copy link

mochetts commented Mar 13, 2024

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:

  • This is not a usage question, this is a bug report
  • This bug can be reproduced with the script I provide below
  • This bug can be reproduced in the latest release of the paper_trail gem

Due 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.

  1. Checkout this repository:
    https://github.com/mochetts/paper-trail-active-storage-bug

  2. Run rails db:migrate to run migrations.

  3. Run rake to run minitests.

  4. See that the test fails:

Screenshot 2024-03-13 at 7 34 08 AM

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.

Screenshot 2024-03-12 at 6 49 20 PM

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.

Screenshot 2024-03-13 at 7 28 02 AM

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.

@mochetts
Copy link
Author

mochetts commented Mar 13, 2024

Note that this issue doesn't happen if you turn off version creation on touch events.

As in:

class User < ApplicationRecord
  has_paper_trail on: %i[create update destroy]
end

@hasannadeem
Copy link

I'm facing the same issue

@yfxie
Copy link

yfxie commented May 8, 2024

@mochetts typo should be destroy

Copy link

github-actions bot commented Aug 7, 2024

This issue has been automatically marked as stale due to inactivity.
The resources of our volunteers are limited.
Bug reports must provide a script that reproduces the bug, using our template. Feature suggestions must include a promise to build the feature yourself.
Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Aug 7, 2024
@aejohnmartin
Copy link

aejohnmartin commented Aug 13, 2024

I am also seeing this issue when using Action Text, i.e. a model with has_rich_text :foobar and has_paper_trail

@github-actions github-actions bot removed the Stale label Aug 14, 2024
Copy link

This issue has been automatically marked as stale due to inactivity.
The resources of our volunteers are limited.
Bug reports must provide a script that reproduces the bug, using our template. Feature suggestions must include a promise to build the feature yourself.
Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Nov 12, 2024
@jagthedrummer
Copy link

Not stale.

@github-actions github-actions bot removed the Stale label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants