-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore(aci): handle OrganizationMember.DoesNotExist when getting target #102113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
I assumed it would be like what happens if we return None for team. Will double check! |
Codecov Report❌ Patch coverage is
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 |
If there is no org member associated with this user and organization, then we should exit gracefully.