Edgewall Software
Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#11672 closed defect (fixed)

Deleting a milestone should delete its attachments

Reported by: Peter Suter Owned by: Peter Suter
Priority: normal Milestone: 0.12.6
Component: roadmap Version: 0.12.5
Severity: normal Keywords: attachment delete milestone
Cc: Branch:
Release Notes:

Deleting a milestone now also deletes its attachments.

API Changes:

Milestone.delete() now also deletes its attachments.

Internal Changes:

Description (last modified by Peter Suter)

Deleting a milestone does not delete its attachments. (As previously discussed.)

Proposed fix:

  • trac/ticket/model.py

    diff -r 19ce84254a0a trac/ticket/model.py
    a b  
    10111011        with self.env.db_transaction as db:
    10121012            self.env.log.info("Deleting milestone %s", self.name)
    10131013            db("DELETE FROM milestone WHERE name=%s", (self.name,))
     1014            Attachment.delete_all(self.env, self.realm, self.name)
    10141015            # Don't translate ticket comment (comment:40:ticket:5658)
    10151016            self.move_tickets(retarget_to, author, "Milestone deleted")
    10161017            self._old['name'] = None

Reparenting of attachments when a milestone is renamed was previously fixed in #7933 and a unit test was added.

A similar unit test should be added for deleting attachments.

Attachments (1)

T11672-delete-milestone-attachments.diff (1.7 KB ) - added by Peter Suter 10 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Peter Suter, 10 years ago

Description: modified (diff)

by Peter Suter, 10 years ago

comment:2 by Peter Suter, 10 years ago

Description: modified (diff)
Owner: set to Peter Suter
Status: newassigned

In the attached patch I rebased the proposed fix for 0.12.6 and added a unit test.

comment:3 by Ryan J Ollos, 10 years ago

Looks good to me. At first I thought this would just leave stray files on the filesystem, but another consequence is that attachments reappear if the milestone is deleted and recreated with the same name.

comment:4 by Peter Suter, 10 years ago

API Changes: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed in [12927] and merged to 1.0-stable ([12928]) and trunk in ([12929]).

comment:5 by Ryan J Ollos, 10 years ago

A side-effect of the defect in this ticket would be that the attachments directory will not be deleted on upgrade for environments in which a milestone with attachment(s) have been deleted: wiki:TracUpgrade#Attachmentsmigratedtonewlocation.

comment:6 by Jun Omae, 10 years ago

The attachments directory will be removed even with the defect because the db28, attachments upgrade, uses only attachment table, so it doesn't check existence of its parent resource.

$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 initenv ticket:11672 sqlite:db/trac.db >/dev/null
$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 milestone add foobar
$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 attachment add milestone:foobar /etc/hosts
$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 attachment list milestone:foobar

Name   Size       Author  Date                 Description
----------------------------------------------------------
hosts  240 bytes  trac    2014-08-18 16:31:43

$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 milestone remove foobar
$ ~/venv/trac/0.12.5/bin/trac-admin /dev/shm/t11672 attachment list milestone:foobar

Name   Size       Author  Date                 Description
----------------------------------------------------------
hosts  240 bytes  trac    2014-08-18 16:31:43

$ sha1sum /dev/shm/t11672/attachments/milestone/foobar/hosts
4e5621cb123edf4834266219aa609bae248096e0  /dev/shm/t11672/attachments/milestone/foobar/hosts
$ ~/venv/trac/1.0.1/bin/trac-admin /dev/shm/t11672 upgrade
Upgrade done.

You may want to upgrade the Trac documentation now by running:

  trac-admin /dev/shm/t11672 wiki upgrade
$ ~/venv/trac/1.0.1/bin/trac-admin /dev/shm/t11672 attachment list milestone:foobar

Name   Size       Author  Date                 Description
----------------------------------------------------------
hosts  240 bytes  trac    2014-08-18 16:31:43

$ ls -ld /dev/shm/t11672/attachments
ls: cannot access /dev/shm/t11672/attachments: No such file or directory
$ ls -l /dev/shm/t11672
total 8
drwxr-xr-x 2 jun66j5 jun66j5 100 Aug 18 16:33 conf
drwxr-xr-x 2 jun66j5 jun66j5  80 Aug 18 16:33 db
drwxr-xr-x 3 jun66j5 jun66j5  60 Aug 18 16:33 files
drwxr-xr-x 2 jun66j5 jun66j5  40 Aug 18 16:31 htdocs
drwxr-xr-x 2 jun66j5 jun66j5  40 Aug 18 16:31 log
drwxr-xr-x 2 jun66j5 jun66j5  40 Aug 18 16:31 plugins
-rw-r--r-- 1 jun66j5 jun66j5  98 Aug 18 16:31 README
drwxr-xr-x 2 jun66j5 jun66j5  60 Aug 18 16:31 templates
-rw-r--r-- 1 jun66j5 jun66j5  27 Aug 18 16:31 VERSION
$ sha1sum /dev/shm/t11672/files/attachments/milestone/884/8843d7f92416211de9ebb963ff4ce28125932878/abba3508de929934a4e4b5198e00683c2b633bbc
4e5621cb123edf4834266219aa609bae248096e0  /dev/shm/t11672/files/attachments/milestone/884/8843d7f92416211de9ebb963ff4ce28125932878/abba3508de929934a4e4b5198e00683c2b633bbc

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Suter.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Peter Suter to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.