Mercurial > libervia-pubsub
diff sat_pubsub/backend.py @ 415:4179ed660a85
backend: fixed publishing with "consistent_publisher" when no item was previously available
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 23 Aug 2019 17:27:26 +0200 |
parents | ccb2a22ea0fc |
children | 794593086517 |
line wrap: on
line diff
--- a/sat_pubsub/backend.py Fri Aug 16 12:53:33 2019 +0200 +++ b/sat_pubsub/backend.py Fri Aug 23 17:27:26 2019 +0200 @@ -457,19 +457,22 @@ if affiliation == 'owner' or self.isAdmin(requestor): if configuration[const.OPT_CONSISTENT_PUBLISHER]: pub_map = yield node.getItemsPublishers(itemIdentifiers) - publishers = set(pub_map.values()) - if len(publishers) != 1: - # TODO: handle multiple items publishing (from several - # publishers) - raise error.NoPublishing( - "consistent_publisher is currently only possible when " - "publishing items from a single publisher. Try to " - "publish one item at a time") - # we replace requestor and new payload's publisher by original - # item publisher to keep publisher consistent - requestor = publishers.pop() - for item in items: - item['publisher'] = requestor.full() + if pub_map: + # if we have existing items, we replace publishers with + # original one to stay consistent + publishers = set(pub_map.values()) + if len(publishers) != 1: + # TODO: handle multiple items publishing (from several + # publishers) + raise error.NoPublishing( + "consistent_publisher is currently only possible when " + "publishing items from a single publisher. Try to " + "publish one item at a time") + # we replace requestor and new payload's publisher by original + # item publisher to keep publisher consistent + requestor = publishers.pop() + for item in items: + item['publisher'] = requestor.full() else: # we don't want a publisher to overwrite the item # of an other publisher