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

Fixes ActiveStorage#has_many_attached re-creating destroyed attachment #42224

Conversation

abhaynikam
Copy link
Contributor

fixes #41862

ActiveStorage#has_many_attached with config.active_storage.replace_on_assign_to_many = false
flag set to flase always appends new attachments to the association.
As mentioned in the issue, if you use nested attributes along with
flag disabled and mark some of the attachment to be destroyed?.
The attachment is destroyed but get re-created without blob upload.
This also results in ActiveStorage#purge_job failing with rollback.

This PR intends to resolve the issue by checking if the attachment is
persisted when #save is invoked. Only persisted and attachment
records are saved which patches the issues.

fixes rails#41862

ActiveStorage#has_many_attached with `config.active_storage.replace_on_assign_to_many = false`
flag set to flase always appends new attachments to the association.
As mentioned in the issue, if you use nested attributes along with
flag disabled and mark some of the attachment to be `destroyed?`.
The attachment is destroyed but get re-created without blob upload.
This also results in `ActiveStorage#purge_job` failing with rollback.

This PR intends to resolve the issue by checking if the attachment is
persisted when `#save` is invoked. Only persisted and attachment
records are saved which patches the issues.
@abhaynikam abhaynikam force-pushed the 41862-active-storage-has-many-attached-with-nested-attributes branch from e37ce2a to 15d5b75 Compare May 14, 2021 14:45
@eileencodes eileencodes merged commit 356916b into rails:main May 14, 2021
@abhaynikam abhaynikam deleted the 41862-active-storage-has-many-attached-with-nested-attributes branch May 14, 2021 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants