Defect #38966
openAttachments custom fields not removed when issue deleted
Added by salman mp 11 months ago. Updated about 2 months ago.
0%
Description
Hi
Attachments of an issue that are related to custom fields of type attachment, get not deleted after issue deletion.
Files
remove_attachment_cf_values.patch (1.24 KB) remove_attachment_cf_values.patch | salman mp, 2023-09-06 23:32 | ||
fix-38966-remove_attachment_after_custom_value_deleted.patch (2.81 KB) fix-38966-remove_attachment_after_custom_value_deleted.patch | Takenori TAKAKI, 2023-09-07 08:09 | ||
20240523085253_remove_orphaned_custom_value_attachments.rb (317 Bytes) 20240523085253_remove_orphaned_custom_value_attachments.rb | Go MAEDA, 2024-05-23 11:15 |
Updated by Takenori TAKAKI 10 months ago
- File fix-38966-remove_attachment_after_custom_value_deleted.patch fix-38966-remove_attachment_after_custom_value_deleted.patch added
I would like to propose a patch and test code to delete the Attachment after the custom value has been removed.
Updated by Takenori TAKAKI 10 months ago
salman mp wrote in #note-4:
Takenori TAKAKI wrote in #note-3:
I would like to propose a patch and test code to delete the Attachment after the custom value has been removed.
Thanks. It's better than mine.
Thanks salman mp ! Looks like we both had the same idea around the same time. Really appreciate your feedback!
Updated by salman mp 7 months ago
Go MAEDA wrote in #note-6:
Thank you for posting the fix. Should we add a migration to delete orphaned objects?
Good idea. Because, if that orphaned objects not destroyed here, no one will destroy them in the future even by attachment:prune
rake task.
It this sufficient?
class RemoveOrphanedCustomValueAttachments < ActiveRecord::Migration[6.1]
def up
Attachment.where(container_type: "CustomValue").each do |a|
a.destroy! if a.container.nil?
end
end
def down
# no-op
end
end
Updated by Go MAEDA about 2 months ago
- File 20240523085253_remove_orphaned_custom_value_attachments.rb 20240523085253_remove_orphaned_custom_value_attachments.rb added
salman mp, thank you for posting the migration file.
I think the attached migration is more efficient than iterating over all attachments returned by Attachment.where(container_type: "CustomValue")
.
Updated by Go MAEDA about 2 months ago
- Target version changed from Candidate for next major release to 6.0.0
Setting the target version to 6.0.0.