Skip to content

Commit ea188e2

Browse files
authored
fix(replay): Add handling for null max_segment_id (#93989)
When the max segment ID is null the process fails. We should exit early since if there aren't any segments to delete there's nothing to do.
1 parent c9fee3f commit ea188e2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/sentry/replays/usecases/delete.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def _delete_if_exists(filename: str) -> None:
8484

8585

8686
def _make_recording_filenames(project_id: int, row: MatchedRow) -> list[str]:
87+
# Null segment_ids can cause this to fail. If no segments were ingested then we can skip
88+
# deleting the segements.
89+
if row["max_segment_id"] is None:
90+
return []
91+
8792
# We assume every segment between 0 and the max_segment_id exists. Its a waste of time to
8893
# delete a non-existent segment but its not so significant that we'd want to query ClickHouse
8994
# to verify it exists.
@@ -104,7 +109,7 @@ def _make_recording_filenames(project_id: int, row: MatchedRow) -> list[str]:
104109
class MatchedRow(TypedDict):
105110
retention_days: int
106111
replay_id: str
107-
max_segment_id: int
112+
max_segment_id: int | None
108113
platform: str
109114

110115

tests/sentry/replays/tasks/test_delete_replays_bulk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_run_bulk_replay_delete_job_completion(self, mock_delete_matched_rows, m
9494
{
9595
"retention_days": 90,
9696
"replay_id": "b",
97-
"max_segment_id": 0,
97+
"max_segment_id": None,
9898
"platform": "javascript",
9999
},
100100
],

0 commit comments

Comments
 (0)