Gracefully handle replies on comments on deleted nodes.

This commit is contained in:
2016-11-03 17:45:19 +01:00
parent 0a0db88701
commit 84a86a690e

View File

@@ -64,17 +64,25 @@ def homepage():
random_featured = get_random_featured_nodes() random_featured = get_random_featured_nodes()
# Parse results for replies # 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: if comment.properties.is_reply:
try:
comment.attached_to = Node.find(comment.parent.parent, comment.attached_to = Node.find(comment.parent.parent,
{'projection': { {'projection': {
'_id': 1, '_id': 1,
'name': 1, 'name': 1,
}}, }},
api=api) api=api)
except ResourceNotFound:
# Remove this comment
to_remove.append(idx)
else: else:
comment.attached_to = comment.parent 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 = Project.find(current_app.config['MAIN_PROJECT_ID'], api=api)
main_project.picture_header = get_file(main_project.picture_header, api=api) main_project.picture_header = get_file(main_project.picture_header, api=api)