Skip to content

Commit f193f7e

Browse files
authored
fix(deletions): Try next available group and abort if none found (#95331)
Fixes [SENTRY-45X2](https://sentry.sentry.io/issues/6731915490/) Fixes [SENTRY-43KR](https://sentry.sentry.io/issues/6710200116/)
1 parent d0aeb2e commit f193f7e

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ module = [
464464
"tests.sentry.api.endpoints.test_project_repo_path_parsing",
465465
"tests.sentry.api.helpers.test_error_upsampling",
466466
"tests.sentry.audit_log.services.*",
467+
"tests.sentry.deletions.tasks.test_groups",
467468
"tests.sentry.deletions.test_group",
468469
"tests.sentry.event_manager.test_event_manager",
469470
"tests.sentry.grouping.seer_similarity.test_get_seer_similar_issues",

src/sentry/deletions/tasks/groups.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ def delete_groups(
3939
from sentry import deletions, eventstream
4040
from sentry.models.group import Group
4141

42-
first_group = Group.objects.get(id=object_ids[0])
42+
max_batch_size = 100
43+
current_batch, rest = object_ids[:max_batch_size], object_ids[max_batch_size:]
44+
45+
# Select first_group from current_batch to ensure project_id tag reflects the current batch
46+
first_group = Group.objects.filter(id__in=current_batch).order_by("id").first()
47+
if not first_group:
48+
raise DeleteAborted("delete_groups.no_group_found")
49+
4350
# The tags can be used if we want to find errors for when a task fails
4451
sentry_sdk.set_tags(
4552
{
@@ -48,8 +55,6 @@ def delete_groups(
4855
},
4956
)
5057

51-
max_batch_size = 100
52-
current_batch, rest = object_ids[:max_batch_size], object_ids[max_batch_size:]
5358
transaction_id = transaction_id or uuid4().hex
5459

5560
logger.info(

tests/sentry/deletions/tasks/test_groups.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from uuid import uuid4
22

3+
import pytest
4+
35
from sentry import nodestore
46
from sentry.deletions.tasks.groups import delete_groups
57
from sentry.eventstore.models import Event
8+
from sentry.exceptions import DeleteAborted
69
from sentry.models.group import Group, GroupStatus
710
from sentry.models.groupassignee import GroupAssignee
811
from sentry.models.grouphash import GroupHash
@@ -17,7 +20,7 @@
1720

1821

1922
class DeleteGroupTest(TestCase):
20-
def test_simple(self):
23+
def test_simple(self) -> None:
2124
event_id = "a" * 32
2225
event_id_2 = "b" * 32
2326
project = self.create_project()
@@ -65,3 +68,22 @@ def test_simple(self):
6568
assert not Group.objects.filter(id=group.id).exists()
6669
assert not nodestore.backend.get(node_id)
6770
assert not nodestore.backend.get(node_id_2)
71+
72+
def test_first_group_not_found(self) -> None:
73+
group = self.create_group()
74+
group2 = self.create_group()
75+
group_ids = [group.id, group2.id]
76+
group.delete()
77+
78+
with self.tasks():
79+
delete_groups(object_ids=group_ids)
80+
81+
assert Group.objects.count() == 0
82+
83+
def test_no_first_group_found(self) -> None:
84+
group = self.create_group()
85+
group_ids = [group.id]
86+
group.delete()
87+
88+
with self.tasks(), pytest.raises(DeleteAborted):
89+
delete_groups(object_ids=group_ids)

0 commit comments

Comments
 (0)