From 3a83a6ae69ac0f6017b1cc3c71ac569d88642147 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 18 Dec 2024 16:12:51 -0600 Subject: [PATCH] Resolve synchronous function running in the Async Slack Socket Mode (#350) * Wrap get_commands_registry with sync_to_async * Move Pull Request Template so that Github picks this up. * Update changes/348.fixed Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com> --------- Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com> --- .../pull_request_template.md => PULL_REQUEST_TEMPLATE.md} | 0 changes/348.fixed | 1 + nautobot_chatops/sockets/slack.py | 7 ++++--- 3 files changed, 5 insertions(+), 3 deletions(-) rename .github/{PULL_REQUEST_TEMPLATE/pull_request_template.md => PULL_REQUEST_TEMPLATE.md} (100%) create mode 100644 changes/348.fixed 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 diff --git a/changes/348.fixed b/changes/348.fixed new file mode 100644 index 00000000..ccd908f9 --- /dev/null +++ b/changes/348.fixed @@ -0,0 +1 @@ +Fixed failure when running slack socket mode. 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))