django / django-contrib-comments

BSD 3-Clause "New" or "Revised" License
614 stars 196 forks source link

Add manage.py delete_stale_comments command #157

Closed atodorov closed 3 years ago

atodorov commented 4 years ago

Because object_pk doesn't enforce cascade delete on the DB level and because some projects may not realize that (I certainly didn't initially) you can end up with lots of comments in the database which don't reference anything anymore.

That was a case with one of my big users and after some backup/restore on their side + a bug in my app itself they ended up with old comments showing up all over the place.

This commands makes it easier for an admin to inspect/remove possible stale comments.

@claudep, @jacobian please review.

claudep commented 3 years ago

Sorry for the long delay, do you think you would be able to add a test?

atodorov commented 3 years ago

Sorry for the long delay, do you think you would be able to add a test?

Do you have anything particular in mind? ATM I can only think of a test which uses call_command() and runs this command in non verbose mode/default answers to yes and then verify that orphaned comments have been deleted. Will work on this in the next few days.

atodorov commented 3 years ago

History & docs updated.

claudep commented 3 years ago

Thanks a lot Alexander for this contribution.