From 3dee9a9251c6e167d0b57c659295d71624aa6ee9 Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 12 Jun 2019 19:31:20 -0600 Subject: [PATCH] Fix issues with "uninteresting" replies This would crash if any (or all) of the replies returned None, since max() can't handle None values. --- .../topic_interesting_activity_updater.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tildes/consumers/topic_interesting_activity_updater.py b/tildes/consumers/topic_interesting_activity_updater.py index aadc890..217d5c9 100644 --- a/tildes/consumers/topic_interesting_activity_updater.py +++ b/tildes/consumers/topic_interesting_activity_updater.py @@ -55,12 +55,16 @@ class TopicInterestingActivityUpdater(PgsqlQueueConsumer): comment_time = None # find the max interesting time from all of this comment's replies + reply_time = None if comment.replies: - reply_time = max( - [self._find_last_interesting_time(reply) for reply in comment.replies] - ) - else: - reply_time = None + reply_times = [ + self._find_last_interesting_time(reply) for reply in comment.replies + ] + try: + reply_time = max([time for time in reply_times if time]) + except ValueError: + # all reply_times were None, just fall through + pass # disregard either time if it's None (or both) potential_times = [time for time in (comment_time, reply_time) if time]