Deleting Comments from Tickets in Trac

Spammers apparently love Trac. After trying to fighting spam tickets and later installing the SpamFilter plugin, I’ve managed to control spam tickets in the Open Yahtzee Trac site.. But now spammers started spamming in the ticket comments. The bad news is that Trac (at least in version 0.11) doesn’t have built-in facilities to completely remove ticket comments.

The solution is to directly delete them from Trac’s SQLite backend. There are several type of comments: Plain ones and comments that describe a change to the ticket’s properties. I’ll deal with only the plain comments, but the methods I describe should also be applicable to the other kinds.

First things you should note down the ticket number and the comment number. The comment number appears in the URL of the permalink to it. It is the number that is pointed by an arrow in the screenshot above, it will be displayed when you hover over the circled link. Now in the shell, cd to the db directory of you trac installation and do:

sqlite3 trac.db "delete from ticket_change where ticket=<TICKET NUM> and field='comment' and oldvalue=<COMMENT NUM>"

For example for the ticket in the screenshot:

sqlite3 trac.db "delete from ticket_change where ticket=12 and field='comment' and oldvalue=3"

You can delete different kinds of tickets by using other values in the field column, such as keywords and summary. Another useful column is the author column.

2 thoughts on “Deleting Comments from Tickets in Trac”

  1. This was definitely useful, not sure why trac’s own website doesn’t show up on google first, but thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.