-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix ActiveStorage has_many_attached when record is not persisted #42383
Fix ActiveStorage has_many_attached when record is not persisted #42383
Conversation
@zzak @pixeltrix Could you please take a look and LMK your take on this 🙇 ? |
@intrip I think of delete/purge as a The fact that we have to define |
@zzak thanks for the feedback!
Gotcha, let's reason together around it:
Your proposal is to create two new classes LMK your thoughts and please forgive me if I'm overlooking at something. |
@intrip Thanks for thinking about this, and apologies for a half-baked response it was at the end of my day 😅 I think we're on the same page, we would have to add two new classes for the Would you mind giving that some more thought and maybe trying it out? |
a0d6549
to
d020c47
Compare
def purge | ||
each(&:purge) | ||
reset | ||
end | ||
|
||
def purge_later | ||
each(&:purge_later) | ||
reset | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this:
- This extension is no longer called from the
Attached
API - I didn't see any documentation explicitly referring to
#{name}_attachments.purge/purge_later
- No tests are using this extension explicitly
For the above reasons shouldn't be a breaking change and allows us to avoid a maintenance burden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@intrip Are these public API? We could add a deprecation (in a follow-up PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I'm not sure (hence my comment above): Is public API a method which has public
visibility but is not documented and doesn't have an explicitly # :nodoc:
comment? 🤷♂️
@zzak I've followed your suggestion in #42383 (comment) Could you please check again ? |
d020c47
to
f2f57b0
Compare
217d6f7
to
4a99f2c
Compare
@zzak thanks! |
I think we should not remove the Unless the parent class/module is already But perhaps @pixeltrix has some more ideas here, particularly w/r/t this thread: #42383 (comment) Raising this in the comments since it's easy for code-threads to get lost 😭 |
4a99f2c
to
f490b8e
Compare
@zzak I've postponed the removal of Please LMK if you have anything else to add 🙇 |
@intrip Nice work! Thanks for putting this together 🙏 |
This is a follow up of rails#42256. Purging a not persisted record no longer raise an error for `has_many_attached`. Moves the `purge` and `purge_later` logic of `ActiveStorage::Attached` to `Attached::Changes` API.
f490b8e
to
a8a6065
Compare
@intrip @zzak thanks for sorting this out 👍🏻 Just one thing before I merge - are the association extensions rails/activestorage/lib/active_storage/attached/model.rb Lines 156 to 166 in 6d3acaf
|
@pixeltrix thanks for checking!
Yes: If you check #42383 (comment) I've proposed to remove that but we weren't sure if we should do it in this PR or we should do it in two separate PRs with a deprecation warning + removal after a new release. What's your take on this? |
Hmm, so those methods would only be called now if you call the association directly - not sure how much that code path would've been used but @zzak is right, we should deprecate them first. |
@pixeltrix thanks for feedback. I'll make a follow-up PR which introduces the deprecation warning. |
@intrip thanks! 👍🏻 |
Summary
This is a follow up of #42256.
Purging a not persisted record no longer raise an error for
has_many_attached
.Moves the
purge
andpurge_later
logic ofActiveStorage::Attached
toAttached::Changes
API.