Commits

David Chambers committed a376d6d

Fixed `UnboundLocalError`.

  • Participants
  • Parent commits 59e233a

Comments (0)

Files changed (1)

         return http.HttpResponseBadRequest('Invalid API key.',
                 content_type=PLAIN)
 
+    cache_key = None
     post_id = request.GET.get('post_id')
     thread_id = request.GET.get('thread_id')
 
 
         for thread in DISQUS.get_thread_list(FORUM, limit=9999):
             if thread.id == thread_id:
+                cache_key = 'mango:disqus:%s' % thread.id
                 break
         else:
             return http.HttpResponseBadRequest('Invalid thread id.', content_type=PLAIN)
 
-    cache_key = 'mango:disqus:%s' % thread.id
-
     if action == 'close':
         DISQUS.update_thread(FORUM, thread, allow_comments=False)
         message = 'Thread closed.'
         message = 'Comment approved.'
         comment.thread.url = request.GET.get('url', comment.thread.url)
 
-        cache.delete(cache_key)
-        logger.debug('Cache key invalidated: %s' % cache_key)
+        if cache_key:
+            cache.delete(cache_key)
+            logger.debug('Cache key invalidated: %s' % cache_key)
 
         if SUBSCRIPTIONS and comment.thread.url: # notify subscribers
             subject = u'New comment on "%s"' % comment.thread.title
         DISQUS.moderate_post(post_id, 'kill')
         message = 'Comment deleted.'
 
-        if not COMMENTS_REQUIRE_APPROVAL:
+        if cache_key and not COMMENTS_REQUIRE_APPROVAL:
             cache.delete(cache_key)
             logger.debug('Cache key invalidated: %s' % cache_key)