From 84a86a690e3a16581879163ed70ecc5be8c25474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 3 Nov 2016 17:45:19 +0100 Subject: [PATCH] Gracefully handle replies on comments on deleted nodes. --- pillar/web/main/routes.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pillar/web/main/routes.py b/pillar/web/main/routes.py index 58cd58d6..2db131c4 100644 --- a/pillar/web/main/routes.py +++ b/pillar/web/main/routes.py @@ -64,17 +64,25 @@ def homepage(): random_featured = get_random_featured_nodes() # Parse results for replies - for comment in latest_comments._items: + to_remove = [] + for idx, comment in enumerate(latest_comments._items): if comment.properties.is_reply: - comment.attached_to = Node.find(comment.parent.parent, - {'projection': { - '_id': 1, - 'name': 1, - }}, - api=api) + try: + comment.attached_to = Node.find(comment.parent.parent, + {'projection': { + '_id': 1, + 'name': 1, + }}, + api=api) + except ResourceNotFound: + # Remove this comment + to_remove.append(idx) else: comment.attached_to = comment.parent + for idx in reversed(to_remove): + del latest_comments._items[idx] + main_project = Project.find(current_app.config['MAIN_PROJECT_ID'], api=api) main_project.picture_header = get_file(main_project.picture_header, api=api)