#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: |
|
||
Internal Changes: |
Description (last modified by )
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 1011 1011 with self.env.db_transaction as db: 1012 1012 self.env.log.info("Deleting milestone %s", self.name) 1013 1013 db("DELETE FROM milestone WHERE name=%s", (self.name,)) 1014 Attachment.delete_all(self.env, self.realm, self.name) 1014 1015 # Don't translate ticket comment (comment:40:ticket:5658) 1015 1016 self.move_tickets(retarget_to, author, "Milestone deleted") 1016 1017 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)
Change History (7)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
by , 10 years ago
Attachment: | T11672-delete-milestone-attachments.diff added |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|---|
Owner: | set to |
Status: | new → assigned |
comment:3 by , 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 , 10 years ago
comment:5 by , 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 , 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
In the attached patch I rebased the proposed fix for 0.12.6 and added a unit test.