From f7bdcf3d3686a67d1ddbb0e790a777a9b82ad6d6 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Fri, 1 Sep 2023 15:47:10 +0100 Subject: [PATCH] Fix `SlackMessage._alert_group` issue (#2945) # What this PR does Fixes https://github.com/grafana/oncall-private/issues/2091 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- .../scenarios/slack_channel_integration.py | 8 ++++- .../test_slack_channel_integration.py | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/engine/apps/slack/scenarios/slack_channel_integration.py b/engine/apps/slack/scenarios/slack_channel_integration.py index 7a2eea9c..045ccbf7 100644 --- a/engine/apps/slack/scenarios/slack_channel_integration.py +++ b/engine/apps/slack/scenarios/slack_channel_integration.py @@ -1,6 +1,8 @@ import logging import typing +from django.core.exceptions import ObjectDoesNotExist + from apps.slack.scenarios import scenario_step from apps.slack.types import EventPayload, EventType, MessageEventSubtype, PayloadType, ScenarioRoute @@ -71,7 +73,11 @@ class SlackChannelMessageEventStep(scenario_step.ScenarioStep): except SlackMessage.DoesNotExist: return - alert_group = slack_message.get_alert_group() + try: + alert_group = slack_message.get_alert_group() + except ObjectDoesNotExist: + # SlackMessage instances without alert_group set (e.g., SSR Slack messages) + return result = self._slack_client.api_call( "chat.getPermalink", diff --git a/engine/apps/slack/tests/test_scenario_steps/test_slack_channel_integration.py b/engine/apps/slack/tests/test_scenario_steps/test_slack_channel_integration.py index 6cc01525..05bfe06d 100644 --- a/engine/apps/slack/tests/test_scenario_steps/test_slack_channel_integration.py +++ b/engine/apps/slack/tests/test_scenario_steps/test_slack_channel_integration.py @@ -437,3 +437,36 @@ class TestSlackChannelMessageEventStep: ).count() == 0 ) + + def test_slack_message_has_no_alert_group( + self, + make_organization_and_user_with_slack_identities, + make_slack_message, + ) -> None: + """Thread messages for SlackMessage instances without alert_group set (e.g., SSR Slack messages)""" + ( + organization, + user, + slack_team_identity, + slack_user_identity, + ) = make_organization_and_user_with_slack_identities() + + channel = "potato" + ts = 88945.4849 + thread_ts = 16789.123 + + payload = { + "event": { + "channel": channel, + "ts": ts, + "thread_ts": thread_ts, + "text": "hello", + }, + } + + make_slack_message(alert_group=None, organization=organization, slack_id=thread_ts, channel_id=channel) + + step = SlackChannelMessageEventStep(slack_team_identity, organization, user) + step.process_scenario(slack_user_identity, slack_team_identity, payload) + + assert not ResolutionNoteSlackMessage.objects.exists()