Skip to content

Commit 59d690c

Browse files
committed
feat(issue-platform): Use assignee passed to the issue platform to assign to group
This hooks up the new assignee that we pass to the issue platform to actually perform the assignment
1 parent d1d0ce6 commit 59d690c

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/sentry/issues/ingest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from sentry.eventstore.models import Event, GroupEvent, augment_message_with_occurrence
2525
from sentry.issues.grouptype import FeedbackGroup, should_create_group
2626
from sentry.issues.issue_occurrence import IssueOccurrence, IssueOccurrenceData
27+
from sentry.models.groupassignee import GroupAssignee
2728
from sentry.models.grouphash import GroupHash
2829
from sentry.models.release import Release
2930
from sentry.ratelimits.sliding_windows import RedisSlidingWindowRateLimiter, RequestedQuota
@@ -237,6 +238,15 @@ def save_issue_from_occurrence(
237238
"sdk": normalized_sdk_tag_from_event(event),
238239
},
239240
)
241+
if is_new and occurrence.assignee:
242+
try:
243+
# Since this calls hybrid cloud it has to be run outside the transaction
244+
assignee = occurrence.assignee.resolve()
245+
except Exception:
246+
logger.exception("Failed to resolve assignee for occurrence")
247+
else:
248+
GroupAssignee.objects.assign(group, assignee, create_only=True)
249+
240250
else:
241251
group = existing_grouphash.group
242252
if group.issue_category.value != occurrence.type.category:

tests/sentry/issues/test_ingest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from sentry.models.environment import Environment
2828
from sentry.models.group import Group
29+
from sentry.models.groupassignee import GroupAssignee
2930
from sentry.models.groupenvironment import GroupEnvironment
3031
from sentry.models.grouprelease import GroupRelease
3132
from sentry.models.release import Release
@@ -147,6 +148,23 @@ def test_new_group_with_priority(self) -> None:
147148
assert group_info is not None
148149
assert group_info.group.priority == PriorityLevel.HIGH
149150

151+
def test_new_group_with_user_assignee(self) -> None:
152+
event = self.store_event(data={}, project_id=self.project.id)
153+
occurrence = self.build_occurrence(event_id=event.event_id, assignee=f"user:{self.user.id}")
154+
_, group_info = save_issue_occurrence(occurrence.to_dict(), event)
155+
assert group_info is not None
156+
assert group_info.group.priority == PriorityLevel.LOW
157+
assignee = GroupAssignee.objects.get(group=group_info.group)
158+
assert assignee.user_id == self.user.id
159+
160+
def test_new_group_with_team_assignee(self) -> None:
161+
event = self.store_event(data={}, project_id=self.project.id)
162+
occurrence = self.build_occurrence(event_id=event.event_id, assignee=f"team:{self.team.id}")
163+
_, group_info = save_issue_occurrence(occurrence.to_dict(), event)
164+
assert group_info is not None
165+
assignee = GroupAssignee.objects.get(group=group_info.group)
166+
assert assignee.team_id == self.team.id
167+
150168

151169
class ProcessOccurrenceDataTest(OccurrenceTestMixin, TestCase):
152170
def test(self) -> None:

tests/sentry/issues/test_occurrence_consumer.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
_process_message,
2222
)
2323
from sentry.models.group import Group
24+
from sentry.models.groupassignee import GroupAssignee
2425
from sentry.receivers import create_default_projects
2526
from sentry.testutils.cases import SnubaTestCase, TestCase
2627
from sentry.testutils.helpers.datetime import before_now, iso_format
@@ -201,6 +202,40 @@ def test_issue_platform_override_priority(self, mock_get_severity_score):
201202
assert group.priority == PriorityLevel.HIGH
202203
assert "severity" not in group.data["metadata"]
203204

205+
def test_new_group_with_user_assignee(self) -> None:
206+
message = get_test_message(self.project.id, assignee=f"user:{self.user.id}")
207+
with self.feature("organizations:profile-file-io-main-thread-ingest"):
208+
result = _process_message(message)
209+
assert result is not None
210+
occurrence = result[0]
211+
assert occurrence is not None
212+
group = Group.objects.filter(grouphash__hash=occurrence.fingerprint[0]).first()
213+
assignee = GroupAssignee.objects.get(group=group)
214+
assert assignee.user_id == self.user.id
215+
216+
def test_new_group_with_team_assignee(self) -> None:
217+
message = get_test_message(self.project.id, assignee=f"team:{self.team.id}")
218+
with self.feature("organizations:profile-file-io-main-thread-ingest"):
219+
result = _process_message(message)
220+
assert result is not None
221+
occurrence = result[0]
222+
assert occurrence is not None
223+
group = Group.objects.filter(grouphash__hash=occurrence.fingerprint[0]).first()
224+
assignee = GroupAssignee.objects.get(group=group)
225+
assert assignee.team_id == self.team.id
226+
227+
def test_new_group_with_invalid_user_assignee(self) -> None:
228+
other_user = self.create_user()
229+
message = get_test_message(self.project.id, assignee=f"user:{other_user.id}")
230+
with self.feature("organizations:profile-file-io-main-thread-ingest"):
231+
result = _process_message(message)
232+
assert result is not None
233+
occurrence = result[0]
234+
assert occurrence is not None
235+
group = Group.objects.filter(grouphash__hash=occurrence.fingerprint[0]).first()
236+
with pytest.raises(GroupAssignee.DoesNotExist):
237+
GroupAssignee.objects.get(group=group)
238+
204239

205240
class IssueOccurrenceLookupEventIdTest(IssueOccurrenceTestBase):
206241
def test_lookup_event_doesnt_exist(self) -> None:

0 commit comments

Comments
 (0)