# HG changeset patch # User Ralph Meijer # Date 1121160180 0 # Node ID 812300cdbc22ec785d5366c7f3e6782af4ebd21d # Parent d2c18d88f618e37949c8fdf85474bef085591a3c Changed behaviour of retraction of items so that only the actually deleted item ids are returned, and no exception is raised for items that didn't actually exists. diff -r d2c18d88f618 -r 812300cdbc22 idavoll/generic_backend.py --- a/idavoll/generic_backend.py Tue Jun 14 12:12:23 2005 +0000 +++ b/idavoll/generic_backend.py Tue Jul 12 09:23:00 2005 +0000 @@ -321,10 +321,10 @@ raise backend.NodeNotPersistent d = node.remove_items(item_ids) - d.addCallback(self._do_notify_retraction, item_ids, node.id) + d.addCallback(self._do_notify_retraction, node.id) return d - def _do_notify_retraction(self, result, item_ids, node_id): + def _do_notify_retraction(self, item_ids, node_id): self.parent.dispatch({ 'item_ids': item_ids, 'node_id': node_id }, '//event/pubsub/retract') diff -r d2c18d88f618 -r 812300cdbc22 idavoll/memory_storage.py --- a/idavoll/memory_storage.py Tue Jun 14 12:12:23 2005 +0000 +++ b/idavoll/memory_storage.py Tue Jul 12 09:23:00 2005 +0000 @@ -164,15 +164,16 @@ deleted = [] for item_id in item_ids: - if not self._items.has_key(item_id): - return defer.fail(storage.ItemNotFound()) - - for item_id in item_ids: - item = self._items[item_id] - self._itemlist.remove(item) - del self._items[item_id] + try: + item = self._items[item_id] + except KeyError: + pass + else: + self._itemlist.remove(item) + del self._items[item_id] + deleted.append(item_id) - return defer.succeed(None) + return defer.succeed(deleted) def get_items(self, max_items=None): if max_items: diff -r d2c18d88f618 -r 812300cdbc22 idavoll/pgsql_storage.py --- a/idavoll/pgsql_storage.py Tue Jun 14 12:12:23 2005 +0000 +++ b/idavoll/pgsql_storage.py Tue Jul 12 09:23:00 2005 +0000 @@ -329,8 +329,10 @@ (self.id, item_id)) - if not cursor.rowcount: - raise storage.ItemNotFound + if cursor.rowcount: + deleted.append(item_id) + + return deleted def get_items(self, max_items=None): return self._dbpool.runInteraction(self._get_items, max_items) diff -r d2c18d88f618 -r 812300cdbc22 idavoll/storage.py --- a/idavoll/storage.py Tue Jun 14 12:12:23 2005 +0000 +++ b/idavoll/storage.py Tue Jul 12 09:23:00 2005 +0000 @@ -17,9 +17,6 @@ class SubscriptionExists(Error): pass -class ItemNotFound(Error): - pass - class IStorage(Interface): """ Storage interface """ @@ -203,8 +200,8 @@ """ Remove items by id @param item_ids: L{list} of item ids. - @return: deferred that fires when all given items were deleted, or - a failure if one of them was not found. + @return: deferred that fires with a L{list} of ids of the items that + were deleted """ def get_items(self, max_items=None): @@ -217,7 +214,7 @@ @param max_items: if given, a natural number (>0) that limits the returned number of items. - @return: deferred that fires with a C{list} of found items. + @return: deferred that fires with a L{list} of found items. """ def get_items_by_id(self, item_ids): @@ -228,7 +225,7 @@ item wrapper with item id. @param item_ids: L{list} of item ids. - @return: deferred that fires with a C{list} of found items. + @return: deferred that fires with a L{list} of found items. """ def purge(self): diff -r d2c18d88f618 -r 812300cdbc22 idavoll/test/test_storage.py --- a/idavoll/test/test_storage.py Tue Jun 14 12:12:23 2005 +0000 +++ b/idavoll/test/test_storage.py Tue Jul 12 09:23:00 2005 +0000 @@ -25,11 +25,6 @@ pubsub.NS_PUBSUB) ITEM_TO_BE_DELETED['id'] = 'to-be-deleted' ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item') -ITEM_TO_NOT_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'), - pubsub.NS_PUBSUB) -ITEM_TO_NOT_BE_DELETED['id'] = 'to-not-be-deleted' -ITEM_TO_NOT_BE_DELETED.addElement(('testns', 'test'), - content=u'Test \u2083 item') def decode(object): if isinstance(object, str): @@ -250,7 +245,8 @@ return d def testRemoveItems(self): - def cb1(void): + def cb1(result): + assertEqual(result, ['to-be-deleted']) return self.node.get_items_by_id(['to-be-deleted']) def cb2(result): @@ -262,8 +258,11 @@ return d def testRemoveNonExistingItems(self): - d = self.node.remove_items(['to-not-be-deleted', 'non-existing']) - assertFailure(d, storage.ItemNotFound) + def cb(result): + assertEqual(result, []) + + d = self.node.remove_items(['non-existing']) + d.addCallback(cb) return d def testGetItems(self): @@ -341,8 +340,6 @@ item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER) self.s._nodes['pre-existing']._items['to-be-deleted'] = item self.s._nodes['pre-existing']._itemlist.append(item) - self.s._nodes['pre-existing']._items['to-not-be-deleted'] = item - self.s._nodes['pre-existing']._itemlist.append(item) self.s._nodes['to-be-purged']._items['to-be-deleted'] = item self.s._nodes['to-be-purged']._itemlist.append(item) item = (decode(ITEM.toXml()), PUBLISHER) @@ -418,14 +415,6 @@ WHERE node='pre-existing'""", (PUBLISHER.userhost(), ITEM_TO_BE_DELETED.toXml())) - cursor.execute("""INSERT INTO items - (node_id, publisher, item, data, date) - SELECT nodes.id, %s, 'to-not-be-deleted', %s, - now() - interval '1 day' - FROM nodes - WHERE node='pre-existing'""", - (PUBLISHER.userhost(), - ITEM_TO_NOT_BE_DELETED.toXml())) cursor.execute("""INSERT INTO items (node_id, publisher, item, data) SELECT nodes.id, %s, 'to-be-deleted', %s FROM nodes