Mercurial > public > sg101
diff gpp/forums/views/main.py @ 318:c550933ff5b6
Fix a bug where you'd get an error when trying to delete a forum thread (topic does not exist). Apparently when you call topic.delete() the posts would get deleted, but the signal handler for each one would run, and it would try to update the topic's post count or something, but the topic was gone? Reworked the code a bit and explicitly delete the posts first. I also added a sync() call on the parent forum since post counts were not getting adjusted.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 Feb 2011 21:46:52 +0000 |
parents | 4f032a6e21f8 |
children | 3f9b9fd54b01 |
line wrap: on
line diff
--- a/gpp/forums/views/main.py Wed Feb 02 20:37:17 2011 +0000 +++ b/gpp/forums/views/main.py Sat Feb 05 21:46:52 2011 +0000 @@ -480,9 +480,10 @@ Note that we don't bother adjusting all the users' post counts as that doesn't seem to be worth the effort. """ - if topic.forum.last_post and topic.forum.last_post.topic == topic: - topic.forum.last_post_pre_delete(deleting_topic=True) - topic.forum.save() + parent_forum = topic.forum + if parent_forum.last_post and parent_forum.last_post.topic == topic: + parent_forum.last_post_pre_delete(deleting_topic=True) + parent_forum.save() # delete subscriptions to this topic topic.subscribers.clear() @@ -493,10 +494,21 @@ for post in posts: post.attachments.clear() - # It should be safe to just delete the topic now. This will - # automatically delete all posts in the topic. + # Null out the topic's last post so we don't have a foreign key pointing + # to a post when we delete posts. + topic.last_post = None + topic.save() + + # delete all posts in bulk + posts.delete() + + # It should be safe to just delete the topic now. topic.delete() + # Resync parent forum's post and topic counts + parent_forum.sync() + parent_forum.save() + @login_required def new_post(request, topic_id):