Revision: 394
Author: bslatkin
Date: Fri Nov  5 17:57:42 2010
Log: hub: fix bug with KnownFeedIdentity recording
http://code.google.com/p/pubsubhubbub/source/detail?r=394

Modified:
 /trunk/hub/main.py
 /trunk/hub/main_test.py

=======================================
--- /trunk/hub/main.py  Fri Nov  5 17:47:09 2010
+++ /trunk/hub/main.py  Fri Nov  5 17:57:42 2010
@@ -2248,9 +2248,6 @@
     else:
       # Expand topic URLs by their feed ID to properly handle any aliases
       # this feed may have active subscriptions for.
-      # TODO(bslatkin): Do something more intelligent here, like collate
-      # all of these topics into a single feed fetch and push, instead of
-      # one separately for each alias the feed may have.
       urls = set()
       for topic, value in topic_map.iteritems():
         urls.update(value)
@@ -2988,6 +2985,8 @@

     order = (ATOM, RSS)
     parse_failures = 0
+    error_traceback = 'Could not determine feed_id'
+    feed_id = None
     for feed_type in order:
       try:
         feed_id = feed_identifier.identify(response.content, feed_type)
@@ -2995,7 +2994,6 @@
           break
         else:
           parse_failures += 1
-          error_traceback = 'Could not determine feed_id'
       except Exception:
         error_traceback = traceback.format_exc()
         logging.debug(
@@ -3003,12 +3001,13 @@
             len(response.content), feed_type, error_traceback)
         parse_failures += 1

-    if parse_failures == len(order) or feed_id is None:
-      logging.warning('Could not record feed ID for topic = %s:\n%s',
-                      topic, error_traceback)
+    if parse_failures == len(order) or not feed_id:
+ logging.warning('Could not record feed ID for topic=%r, feed_id=%r:\n%s',
+                      topic, feed_id, error_traceback)
       known_feed.put()
       # Just give up, since we can't parse it. This case also covers when
-      # the character encoding for the document is unsupported.
+ # the character encoding for the document is unsupported or the document
+      # is of an arbitrary content type.
       return

     logging.info('For topic = %s found new feed ID %r; old feed ID was %r',
=======================================
--- /trunk/hub/main_test.py     Fri Nov  5 17:47:09 2010
+++ /trunk/hub/main_test.py     Fri Nov  5 17:57:42 2010
@@ -4050,6 +4050,15 @@
     feed = KnownFeed.get(KnownFeed.create_key(self.topic))
     self.assertTrue(feed.feed_id is None)

+  def testParseFindsEmptyId(self):
+    """Tests when no SAX exception is raised but the feed ID is empty."""
+ urlfetch_test_stub.instance.expect('GET', self.topic, 200, self.content)
+    self.expected_calls.append((self.content, 'atom'))
+    self.expected_results.append('')
+    self.handle('post', ('topic', self.topic))
+    feed = KnownFeed.get(KnownFeed.create_key(self.topic))
+    self.assertTrue(feed.feed_id is None)
+
   def testExistingFeedNeedsRefresh(self):
"""Tests recording details for an existing feed that needs a refresh."""
     KnownFeed.create(self.topic).put()

Reply via email to