Skip to content

Commit eda2782

Browse files
kddubeypriscilawebdev
authored andcommitted
feat(bug-prediction): Allow short IDs (#102138)
seer-side will let this tool supply short IDs
1 parent c1bf704 commit eda2782

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/sentry/seer/fetch_issues/utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,25 @@ def bulk_serialize_for_seer(groups: list[Group]) -> SeerResponse:
136136
}
137137

138138

139-
def get_latest_issue_event(group_id: int, organization_id: int) -> dict[str, Any]:
139+
def _group_by_short_id(short_id: str, organization_id: int) -> Group | None:
140+
try:
141+
return Group.objects.by_qualified_short_id(organization_id, short_id)
142+
except Group.DoesNotExist:
143+
return None
144+
145+
146+
def get_latest_issue_event(group_id: int | str, organization_id: int) -> dict[str, Any]:
140147
"""
141148
Get an issue's latest event as a dict, matching the Seer IssueDetails model.
142149
"""
143-
group = Group.objects.filter(id=group_id).first()
150+
if isinstance(group_id, str) and not group_id.isdigit():
151+
group = _group_by_short_id(group_id, organization_id)
152+
else:
153+
group = Group.objects.filter(id=int(group_id)).first()
154+
144155
if not group:
145156
logger.warning(
146-
"Group not found",
147-
extra={"group_id": group_id},
157+
"Group not found", extra={"group_id": group_id, "organization_id": organization_id}
148158
)
149159
return {}
150160

tests/sentry/seer/fetch_issues/test_utils.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,33 @@ def test_get_latest_issue_event_success(self):
201201
assert isinstance(result, dict)
202202
assert result["id"] == group.id
203203
assert result["title"] == group.title
204-
assert "events" in result
205204
assert len(result["events"]) == 1
206205
assert result["events"][0]["id"] == event.event_id
207206

208-
def test_get_latest_issue_event_group_not_found(self):
207+
def test_get_latest_issue_event_not_found(self):
209208
nonexistent_group_id = 999999
210209
result = get_latest_issue_event(nonexistent_group_id, self.organization.id)
211210
assert result == {}
212211

212+
def test_get_latest_issue_event_with_short_id(self):
213+
data = load_data("python", timestamp=before_now(minutes=1))
214+
event = self.store_event(data=data, project_id=self.project.id)
215+
group = event.group
216+
217+
assert group is not None
218+
result = get_latest_issue_event(group.qualified_short_id, self.organization.id)
219+
220+
assert result is not None
221+
assert isinstance(result, dict)
222+
assert result["id"] == group.id
223+
assert result["title"] == group.title
224+
assert len(result["events"]) == 1
225+
assert result["events"][0]["id"] == event.event_id
226+
227+
def test_get_latest_issue_event_with_short_id_not_found(self):
228+
result = get_latest_issue_event("INVALID-SHORT-ID", self.organization.id)
229+
assert result == {}
230+
213231
def test_get_latest_issue_event_no_events(self):
214232
# Create a group but don't store any events for it
215233
group = self.create_group(project=self.project)

0 commit comments

Comments
 (0)