Skip to content

Conversation

@mifu67
Copy link
Contributor

@mifu67 mifu67 commented Oct 24, 2025

If there is no org member associated with this user and organization, then we should exit gracefully.

@mifu67 mifu67 requested review from a team as code owners October 24, 2025 22:31
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 24, 2025
Comment on lines +49 to +56
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
Copy link

Choose a reason for hiding this comment

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

Bug: human_desc() receives None for target from MetricAlertRegistryHandler.target() and attempts to access attributes, causing an AttributeError.
Severity: CRITICAL | Confidence: 0.98

🔍 Detailed Analysis

When MetricAlertRegistryHandler.target() returns None due to a caught OrganizationMember.DoesNotExist exception, the WorkflowEngineActionSerializer passes this None value to human_desc(). If the action is an email type (AlertRuleTriggerAction.Type.EMAIL.value) targeting a user or team (AlertRuleTriggerAction.TargetType.USER.value or AlertRuleTriggerAction.TargetType.TEAM.value), human_desc() attempts to call target.get_email() or target.slug on the None object. This occurs when an email action is configured for a user or team member who is subsequently deleted, leading to an AttributeError.

💡 Suggested Fix

Modify human_desc() to check if target is None before attempting to access target.get_email() or target.slug when action_type is email and target_type is user or team.

🤖 Prompt for AI Agent
Fix this bug. In
src/sentry/notifications/notification_action/group_type_notification_registry/handlers/metric_alert_registry_handler.py
at lines 49-56: When `MetricAlertRegistryHandler.target()` returns `None` due to a
caught `OrganizationMember.DoesNotExist` exception, the `WorkflowEngineActionSerializer`
passes this `None` value to `human_desc()`. If the action is an email type
(`AlertRuleTriggerAction.Type.EMAIL.value`) targeting a user or team
(`AlertRuleTriggerAction.TargetType.USER.value` or
`AlertRuleTriggerAction.TargetType.TEAM.value`), `human_desc()` attempts to call
`target.get_email()` or `target.slug` on the `None` object. This occurs when an email
action is configured for a user or team member who is subsequently deleted, leading to
an `AttributeError`.

Did we get this right? 👍 / 👎 to inform future reviews.

@mifu67 mifu67 requested a review from iamrajjoshi October 24, 2025 22:34
Copy link
Collaborator

@iamrajjoshi iamrajjoshi left a comment

Choose a reason for hiding this comment

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

If we return None here, what happens downstream? I think it should be fine and we will go to the fallback if it exists?

@mifu67
Copy link
Contributor Author

mifu67 commented Oct 24, 2025

If we return None here, what happens downstream? I think it should be fine and we will go to the fallback if it exists?

I assumed it would be like what happens if we return None for team. Will double check!

@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...registry/handlers/metric_alert_registry_handler.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #102113      +/-   ##
===========================================
- Coverage   80.95%    80.95%   -0.01%     
===========================================
  Files        8741      8742       +1     
  Lines      388998    389040      +42     
  Branches    24692     24692              
===========================================
+ Hits       314930    314959      +29     
- Misses      73713     73726      +13     
  Partials      355       355              

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants