Project

General

Profile

Actions

Defect #38966

open

Attachments custom fields not removed when issue deleted

Added by salman mp 11 months ago. Updated 2 months ago.

Status:
Confirmed
Priority:
Normal
Assignee:
-
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

Hi
Attachments of an issue that are related to custom fields of type attachment, get not deleted after issue deletion.


Files

Actions #1

Updated by Go MAEDA 11 months ago

  • Status changed from New to Confirmed
Actions #2

Updated by salman mp 11 months ago

As a suggestion, this patch removed attachment custom values before customizable destroy.

Actions #3

Updated by Takenori TAKAKI 11 months ago

I would like to propose a patch and test code to delete the Attachment after the custom value has been removed.

Actions #4

Updated by salman mp 11 months ago

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.

Actions #5

Updated by Takenori TAKAKI 11 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!

Actions #6

Updated by Go MAEDA 7 months ago

  • Target version set to Candidate for next major release

Thank you for posting the fix. Should we add a migration to delete orphaned objects?

Actions #7

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
Actions #8

Updated by Go MAEDA 2 months ago

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").

Actions #9

Updated by Go MAEDA 2 months ago

  • Target version changed from Candidate for next major release to 6.0.0

Setting the target version to 6.0.0.

Actions

Also available in: Atom PDF