Mercurial > public > sg101
changeset 235:d302c498560e
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.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Aug 2010 04:01:58 +0000 |
parents | f53eb0aae7a9 |
children | 953c71f382df |
files | gpp/forums/views/main.py |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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):