Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ def target(action: Action) -> OrganizationMember | Team | str | None:
target_type = action.config.get("target_type")
if target_type == ActionTarget.USER.value:
dcga = DataConditionGroupAction.objects.get(action=action)
return OrganizationMember.objects.get(
user_id=int(target_identifier),
organization=dcga.condition_group.organization,
)
try:
return OrganizationMember.objects.get(
user_id=int(target_identifier),
organization=dcga.condition_group.organization,
)
except OrganizationMember.DoesNotExist:
# user is no longer a member of the organization
pass
Comment on lines +54 to +56

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

The function now exits gracefully when OrganizationMember doesn't exist, but it doesn't return None explicitly. While Python functions return None by default, it's clearer to be explicit about the return value when handling the exception case.

Suggested change
except OrganizationMember.DoesNotExist:
# user is no longer a member of the organization
pass
except OrganizationMember.DoesNotExist:
# user is no longer a member of the organization
return None

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Context for Agents
[**BestPractice**]

The function now exits gracefully when OrganizationMember doesn't exist, but it doesn't return None explicitly. While Python functions return None by default, it's clearer to be explicit about the return value when handling the exception case.

```suggestion
            except OrganizationMember.DoesNotExist:
                # user is no longer a member of the organization
                return None
```

⚡ **Committable suggestion**

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

File: src/sentry/notifications/notification_action/group_type_notification_registry/handlers/metric_alert_registry_handler.py
Line: 56

elif target_type == ActionTarget.TEAM.value:
try:
return Team.objects.get(id=int(target_identifier))
Expand Down