# HG changeset patch # User Brian Neal # Date 1296942412 0 # Node ID c550933ff5b6bbf28de53830e4f85bcc0ec3fcc5 # Parent 2934a867c2ef622461d761d1ee24ee6039d675f7 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. diff -r 2934a867c2ef -r c550933ff5b6 gpp/forums/views/main.py --- 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): diff -r 2934a867c2ef -r c550933ff5b6 gpp/settings.py --- a/gpp/settings.py Wed Feb 02 20:37:17 2011 +0000 +++ b/gpp/settings.py Sat Feb 05 21:46:52 2011 +0000 @@ -83,7 +83,7 @@ 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - #'debug_toolbar.middleware.DebugToolbarMiddleware', + 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'gpp.core.middleware.InactiveUserMiddleware', 'gpp.core.middleware.WhosOnline', @@ -159,8 +159,8 @@ 'smiley', 'weblinks', ] -#if DEBUG: -# INSTALLED_APPS.append('debug_toolbar') +if DEBUG: + INSTALLED_APPS.append('debug_toolbar') LOGIN_URL = '/accounts/login/' LOGIN_REDIRECT_URL = '/profile/me/'