# HG changeset patch # User Brian Neal # Date 1282795318 0 # Node ID d302c498560e5ad110c00f7c588e3c76496452e2 # Parent f53eb0aae7a975efe995ebb9b851992af5560cb2 Fix problem when deleting multiple topics from a forum in bulk. We getting a list of topics from the database, then deleting each topic. But after you delete a topic, the forum.last_post on the remaining non-deleted topics can be stale. This was causing a weird DoesNotExist. Now just get the topics one at a time from the database. diff -r f53eb0aae7a9 -r d302c498560e gpp/forums/views/main.py --- a/gpp/forums/views/main.py Sun Aug 01 22:14:01 2010 +0000 +++ b/gpp/forums/views/main.py Thu Aug 26 04:01:58 2010 +0000 @@ -878,10 +878,19 @@ """ Deletes the list of topics. """ - topics = Topic.objects.filter(pk__in=topic_ids).select_related() - for topic in topics: - if topic.forum == forum: - _delete_topic(topic) + # Because we are deleting stuff, retrieve each topic one at a + # time since we are going to be adjusting de-normalized fields + # during deletes. In particular, we can't do this: + # topics = Topic.objects.filter(pk__in=topic_ids).select_related() + # for topic in topics: + # since topic.forum.last_post can go stale after a delete. + + for id in topic_ids: + try: + topic = Topic.objects.select_related().get(pk=id) + except Topic.DoesNotExist: + continue + _delete_topic(topic) def _bulk_move(topic_ids, old_forum, new_forum):