Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/sentry/deletions/defaults/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Any

from sentry import models, options
from sentry.db.models.base import Model
from sentry.deletions.tasks.nodestore import delete_events_for_groups_from_nodestore_and_eventstore
from sentry.issues.grouptype import GroupCategory, InvalidGroupTypeError
from sentry.models.group import Group, GroupStatus
Expand Down Expand Up @@ -76,6 +75,7 @@
models.GroupEmailThread,
models.GroupSubscription,
models.GroupReaction,
models.Activity,
RuleFireHistory,
)

Expand All @@ -96,16 +96,6 @@
_GROUP_RELATED_MODELS = DIRECT_GROUP_RELATED_MODELS + ADDITIONAL_GROUP_RELATED_MODELS


def get_group_related_models() -> Sequence[type[Model]]:
"""
Returns the tuple of models related to groups that should be deleted.
Checks options at runtime to allow dynamic configuration.
"""
if options.get("deletions.activity.delete-in-bulk"):
return _GROUP_RELATED_MODELS + (models.Activity,)
return _GROUP_RELATED_MODELS


class EventsBaseDeletionTask(BaseDeletionTask[Group]):
"""
Base class to delete events associated to groups and its related models.
Expand Down Expand Up @@ -217,7 +207,7 @@ def _delete_children(self, instance_list: Sequence[Group]) -> None:
group_ids = [group.id for group in instance_list]
# Remove child relations for all groups first.
child_relations: list[BaseRelation] = []
for model in get_group_related_models():
for model in _GROUP_RELATED_MODELS:
child_relations.append(ModelRelation(model, {"group_id__in": group_ids}))

error_groups, issue_platform_groups = separate_by_group_category(instance_list)
Expand Down
6 changes: 0 additions & 6 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,6 @@
type=Bool,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)
register(
"deletions.activity.delete-in-bulk",
default=False,
type=Bool,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"cleanup.abort_execution",
Expand Down
4 changes: 1 addition & 3 deletions src/sentry/reprocessing2.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@

# Group-related models are only a few per-group and are migrated at
# once.
GROUP_MODELS_TO_MIGRATE_RAW = DIRECT_GROUP_RELATED_MODELS + (models.Activity,)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# If we were to move groupinbox to the new, empty group, inbox would show the
# empty, unactionable group while it is reprocessing. Let post-process take
# care of assigning GroupInbox like normally.
GROUP_MODELS_TO_MIGRATE = tuple(x for x in GROUP_MODELS_TO_MIGRATE_RAW if x != models.GroupInbox)
GROUP_MODELS_TO_MIGRATE = tuple(x for x in DIRECT_GROUP_RELATED_MODELS if x != models.GroupInbox)

# Event attachments and group reports are per-event. This means that:
#
Expand Down
6 changes: 6 additions & 0 deletions tests/sentry/deletions/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sentry.deletions.tasks.groups import delete_groups_for_project
from sentry.issues.grouptype import GroupCategory
from sentry.issues.issue_occurrence import IssueOccurrence
from sentry.models.activity import Activity
from sentry.models.eventattachment import EventAttachment
from sentry.models.group import Group
from sentry.models.groupassignee import GroupAssignee
Expand All @@ -26,6 +27,7 @@
from sentry.snuba.referrer import Referrer
from sentry.testutils.cases import SnubaTestCase, TestCase
from sentry.testutils.helpers.datetime import before_now
from sentry.types.activity import ActivityType
from sentry.utils.snuba import bulk_snuba_queries
from tests.sentry.issues.test_utils import OccurrenceTestMixin

Expand Down Expand Up @@ -62,6 +64,9 @@ def _create_event_with_many_group_children(self) -> Event:
GroupHash.objects.create(project=self.project, group=event.group, hash=uuid4().hex)
GroupMeta.objects.create(group=event.group, key="foo", value="bar")
GroupRedirect.objects.create(group_id=event.group.id, previous_group_id=1)
Activity.objects.create(
group=event.group, project=self.project, type=ActivityType.SET_RESOLVED.value
)

return event

Expand All @@ -86,6 +91,7 @@ def test_delete_group_with_many_related_children(self) -> None:
assert not UserReport.objects.filter(event_id=event.event_id).exists()
assert not EventAttachment.objects.filter(event_id=event.event_id).exists()

assert not Activity.objects.filter(group_id=event.group.id).exists()
assert not GroupRedirect.objects.filter(group_id=event.group.id).exists()
assert not GroupHash.objects.filter(group_id=event.group.id).exists()
assert not Group.objects.filter(id=event.group.id).exists()
Expand Down
Loading