# HG changeset patch # User Goffi # Date 1665859113 -7200 # Node ID 2b2856ae5eeb61685e3766304dfbb3774b29af36 # Parent 748094d5a74d36b80ea1d2e21c43ddac23653480 plugin XEP-0470: fix autocreate in `create_attachments_node`: Due to config check, `create_attachments_node` was failing when the target node was not already existing. However, this is the case when an item is published and `autocreate` is expected, thus the node is now created if not already existing and new `autocreate` argument is set. diff -r 748094d5a74d -r 2b2856ae5eeb sat/plugins/plugin_xep_0470.py --- a/sat/plugins/plugin_xep_0470.py Sat Oct 15 20:38:33 2022 +0200 +++ b/sat/plugins/plugin_xep_0470.py Sat Oct 15 20:38:33 2022 +0200 @@ -164,7 +164,9 @@ data: dict ) -> bool: """trigger to create attachment node on each publication""" - await self.create_attachments_node(client, service, node, item["id"]) + await self.create_attachments_node( + client, service, node, item["id"], autocreate=True + ) return True async def create_attachments_node( @@ -172,10 +174,27 @@ client: SatXMPPEntity, service: jid.JID, node: str, - item_id: str + item_id: str, + autocreate: bool = False ): - """Create node for attachements if necessary""" - node_config = await self._p.getConfiguration(client, service, node) + """Create node for attachements if necessary + + @param service: service of target node + @param node: node where target item is published + @param item_id: ID of target item + @param autocrate: if True, target node is create if it doesn't exist + """ + try: + node_config = await self._p.getConfiguration(client, service, node) + except error.StanzaError as e: + if e.condition == "item-not-found" and autocreate: + # we auto-create the missing node + await self._p.createNode( + client, service, node + ) + node_config = await self._p.getConfiguration(client, service, node) + else: + raise e try: # FIXME: check if this is the best publish_model option node_config.fields["pubsub#publish_model"].value = "open"