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)
This commit is contained in:
Vadim Stepanov 2023-09-01 15:47:10 +01:00 committed by GitHub
parent 88c5338ea1
commit f7bdcf3d36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -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",

View file

@ -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()