Project

General

Profile

Actions

Defect #38966

closed

Attachment custom fields not removed when issue is deleted

Defect #38966: Attachment custom fields not removed when issue is deleted

Added by salman mp over 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:
Resolution:
Fixed
Affected version:

Description

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


Files

Updated by Go MAEDA about 3 years ago Actions #1

  • Status changed from New to Confirmed

Updated by salman mp about 3 years ago Actions #2

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

Updated by Takenori TAKAKI about 3 years ago Actions #3

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

Updated by salman mp about 3 years ago Actions #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.

Updated by Takenori TAKAKI about 3 years ago Actions #5

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 @salmanmp ! Looks like we both had the same idea around the same time. Really appreciate your feedback!

Updated by Go MAEDA almost 3 years ago Actions #6

  • Target version set to Candidate for next major release

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

Updated by salman mp almost 3 years ago Actions #7

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 over 2 years ago Actions #8

@salmanmp, 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 over 2 years ago Actions #9

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

Setting the target version to 6.0.0.

Updated by Go MAEDA about 2 years ago Actions #10

I have updated the patch:

  • Added a migration to delete orphaned attachments
  • Changed callback method names to be more descriptive
  • Removed a loop from destroy_custom_value_attachments for improved efficiency

Updated by Takenori TAKAKI about 2 years ago Actions #11

@Go MAEDA
I have confirmed the patch.
The added migration, proper naming and loop removal would be good!

Updated by Go MAEDA about 2 years ago Actions #12

  • Subject changed from Attachments custom fields not removed when issue deleted to Attachment custom fields not removed when issue is deleted
  • Status changed from Confirmed to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix in r23161. Thank you for your contribution.

Actions

Also available in: PDF Atom