IndexError when self.num_items is greater than the entries returned.

Issue #1 new
Daniel Lindsley
created an issue

Especially when there's an error on the other end and the feed comes back empty. Patch below.

{{{

!diff

diff --git a/thirdparty/template_utils/templatetags/feeds.py b/thirdparty/template_utils/templatetags/feeds.py index 5c608d2..8c9870f 100644 --- a/thirdparty/template_utils/templatetags/feeds.py +++ b/thirdparty/template_utils/templatetags/feeds.py @@ -25,7 +25,9 @@ class FeedIncludeNode(template.Node): feed_url = self.feed_url.resolve(context) feed = feedparser.parse(feed_url) items = [] - num_items = int(self.num_items) or len(feed['entries']) + # If there are fewer entries available than were requested, don't + # attempt to access offsets that aren't there. + num_items = min(int(self.num_items), len(feed['entries'])) for i in range(num_items): pub_date = feed['entries'][i].updated_parsed published = datetime.date(pub_date[0], pub_date[1], pub_date[2])

}}}

Comments (0)

  1. Log in to comment