Skip to content

Commit

Permalink
Fix SlackMessage._alert_group issue (#2945)
Browse files Browse the repository at this point in the history
# What this PR does

Fixes  grafana/oncall-private#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)
  • Loading branch information
vstpme authored Sep 1, 2023
1 parent 88c5338 commit f7bdcf3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion engine/apps/slack/scenarios/slack_channel_integration.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -71,7 +73,11 @@ def save_thread_message_for_resolution_note(
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,36 @@ def test_delete_thread_message_from_resolution_note(
).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()

0 comments on commit f7bdcf3

Please sign in to comment.