Skip to content

Commit e35cf9e

Browse files
fix(helpful-event): sort on whether replay_id or profile_id are null or not and not the actual id values (#52777)
Fixes an issue where we sort on the ID values themselves instead of sorting on whether the replay_id or profile_id are present.
1 parent 7f7cc5e commit e35cf9e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/sentry/eventstore/snuba/backend.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ def get_events_snql(
103103
direction=direction,
104104
)
105105
)
106+
elif order_field_alias in (
107+
Columns.PROFILE_ID.value.alias,
108+
Columns.REPLAY_ID.value.alias,
109+
):
110+
resolved_order_by.append(
111+
OrderBy(
112+
Function(
113+
"if", [Function("isNull", [Column(resolved_column_or_none)]), 0, 1]
114+
),
115+
direction=direction,
116+
)
117+
)
106118
else:
107119
resolved_order_by.append(
108120
OrderBy(Column(resolved_column_or_none), direction=direction)

tests/sentry/api/endpoints/test_group_event_details.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,55 @@ def test_get_simple_helpful(self):
175175
assert response.data["previousEventID"] == self.event_c.event_id
176176
assert response.data["nextEventID"] is None
177177

178+
@with_feature("organizations:issue-details-most-helpful-event")
179+
def test_get_helpful_replay_id_order(self):
180+
replay_id_1 = uuid.uuid4().hex
181+
replay_id_2 = uuid.uuid4().hex
182+
replay_id_1 = "b" + replay_id_1[1:]
183+
replay_id_2 = "a" + replay_id_2[1:]
184+
185+
self.event_d = self.store_event(
186+
data={
187+
"event_id": "d" * 32,
188+
"environment": "staging",
189+
"timestamp": iso_format(before_now(minutes=3)),
190+
"fingerprint": ["group-order"],
191+
"contexts": {
192+
"replay": {"replay_id": replay_id_1},
193+
},
194+
},
195+
project_id=self.project_1.id,
196+
)
197+
self.event_e = self.store_event(
198+
data={
199+
"event_id": "e" * 32,
200+
"environment": "staging",
201+
"timestamp": iso_format(before_now(minutes=2)),
202+
"fingerprint": ["group-order"],
203+
"contexts": {
204+
"replay": {"replay_id": replay_id_2},
205+
},
206+
},
207+
project_id=self.project_1.id,
208+
)
209+
self.event_f = self.store_event(
210+
data={
211+
"event_id": "f" * 32,
212+
"environment": "staging",
213+
"timestamp": iso_format(before_now(minutes=1)),
214+
"fingerprint": ["group-order"],
215+
},
216+
project_id=self.project_1.id,
217+
)
218+
219+
url = f"/api/0/issues/{self.event_d.group.id}/events/helpful/"
220+
response = self.client.get(url, format="json")
221+
222+
assert response.status_code == 200, response.content
223+
assert response.data["id"] == str(self.event_e.event_id)
224+
assert response.data["previousEventID"] == str(self.event_d.event_id)
225+
assert response.data["nextEventID"] == str(self.event_f.event_id)
226+
178227
@with_feature("organizations:issue-details-most-helpful-event")
179228
def test_with_empty_query(self):
180229
url = f"/api/0/issues/{self.event_a.group.id}/events/helpful/"

0 commit comments

Comments
 (0)