From 30d1cb951a8a3cac29e345588fb6df85f49978f4 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 18 Dec 2024 10:01:04 -0600 Subject: [PATCH 1/3] Wrap get_commands_registry with sync_to_async --- changes/348.fixed | 1 + nautobot_chatops/sockets/slack.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changes/348.fixed diff --git a/changes/348.fixed b/changes/348.fixed new file mode 100644 index 00000000..95106cd0 --- /dev/null +++ b/changes/348.fixed @@ -0,0 +1 @@ +Resolve the issue of a synchronous function running in the async sockets. diff --git a/nautobot_chatops/sockets/slack.py b/nautobot_chatops/sockets/slack.py index e4482db7..5f95975a 100644 --- a/nautobot_chatops/sockets/slack.py +++ b/nautobot_chatops/sockets/slack.py @@ -4,6 +4,7 @@ import json import shlex +from asgiref.sync import sync_to_async from django.conf import settings from slack_sdk.socket_mode.aiohttp import SocketModeClient from slack_sdk.socket_mode.request import SocketModeRequest @@ -71,7 +72,7 @@ async def process_slash_command(client, req): client.logger.error("%s", err) return - registry = get_commands_registry() + registry = await sync_to_async(get_commands_registry)() if command not in registry: SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX)) @@ -210,7 +211,7 @@ async def process_interactive(client, req): client.logger.info(f"command: {command}, subcommand: {subcommand}, params: {params}") - registry = get_commands_registry() + registry = await sync_to_async(get_commands_registry)() if command not in registry: SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX)) @@ -241,7 +242,7 @@ async def process_mention(client, req): client.logger.error("%s", err) return - registry = get_commands_registry() + registry = await sync_to_async(get_commands_registry)() if command not in registry: SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX)) From f92311cc4623ca350d1f37d71c8c32e0450d43de Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 18 Dec 2024 10:03:09 -0600 Subject: [PATCH 2/3] Move Pull Request Template so that Github picks this up. --- .../pull_request_template.md => PULL_REQUEST_TEMPLATE.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{PULL_REQUEST_TEMPLATE/pull_request_template.md => PULL_REQUEST_TEMPLATE.md} (100%) diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/PULL_REQUEST_TEMPLATE.md From f413c8d5bf2d7fdc769f9308c275b040b5a08c50 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 18 Dec 2024 15:42:06 -0600 Subject: [PATCH 3/3] Update changes/348.fixed Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com> --- changes/348.fixed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/348.fixed b/changes/348.fixed index 95106cd0..ccd908f9 100644 --- a/changes/348.fixed +++ b/changes/348.fixed @@ -1 +1 @@ -Resolve the issue of a synchronous function running in the async sockets. +Fixed failure when running slack socket mode.