Skip to content

Commit 3d2e486

Browse files
authored
chore(aci): handle OrganizationMember.DoesNotExist when getting target (#102113)
If there is no org member associated with this user and organization, then we should exit gracefully.
1 parent e595496 commit 3d2e486

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/sentry/incidents/endpoints/serializers/alert_rule_trigger_action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def human_desc(
3232
return "Send a notification to " + target.get_email()
3333
elif target_type == AlertRuleTriggerAction.TargetType.TEAM.value:
3434
return "Send an email to members of #" + target.slug
35+
else:
36+
return "Send a notification to [removed]"
3537
elif action_type == AlertRuleTriggerAction.Type.OPSGENIE.value:
3638
if priority:
3739
return f"Send a {priority} Opsgenie notification to {target_display}"

src/sentry/notifications/notification_action/group_type_notification_registry/handlers/metric_alert_registry_handler.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ def target(action: Action) -> OrganizationMember | Team | str | None:
4646
target_type = action.config.get("target_type")
4747
if target_type == ActionTarget.USER.value:
4848
dcga = DataConditionGroupAction.objects.get(action=action)
49-
return OrganizationMember.objects.get(
50-
user_id=int(target_identifier),
51-
organization=dcga.condition_group.organization,
52-
)
49+
try:
50+
return OrganizationMember.objects.get(
51+
user_id=int(target_identifier),
52+
organization=dcga.condition_group.organization,
53+
)
54+
except OrganizationMember.DoesNotExist:
55+
# user is no longer a member of the organization
56+
pass
5357
elif target_type == ActionTarget.TEAM.value:
5458
try:
5559
return Team.objects.get(id=int(target_identifier))

0 commit comments

Comments
 (0)