Skip to content

Commit 4fc6206

Browse files
committed
add async deletion for deleting sentry app install directly
1 parent f141386 commit 4fc6206

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/sentry/sentry_apps/api/endpoints/installation_details.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from rest_framework.request import Request
55
from rest_framework.response import Response
66

7-
from sentry import analytics, audit_log, deletions
7+
from sentry import analytics, audit_log
88
from sentry.analytics.events.sentry_app_uninstalled import SentryAppUninstalledEvent
99
from sentry.api.api_owners import ApiOwner
1010
from sentry.api.api_publish_status import ApiPublishStatus
1111
from sentry.api.base import control_silo_endpoint
1212
from sentry.api.serializers import serialize
13+
from sentry.deletions.models.scheduleddeletion import ScheduledDeletion
1314
from sentry.sentry_apps.api.bases.sentryapps import SentryAppInstallationBaseEndpoint
1415
from sentry.sentry_apps.api.parsers.sentry_app_installation import SentryAppInstallationParser
1516
from sentry.sentry_apps.api.serializers.sentry_app_installation import (
@@ -56,7 +57,7 @@ def delete(self, request: Request, installation) -> Response:
5657
# if the error is from a request exception, log the error and continue
5758
except RequestException as exc:
5859
sentry_sdk.capture_exception(exc)
59-
deletions.exec_sync(sentry_app_installation)
60+
ScheduledDeletion.schedule(sentry_app_installation, days=0, actor=request.user)
6061
create_audit_entry(
6162
request=request,
6263
organization_id=sentry_app_installation.organization_id,

tests/sentry/sentry_apps/api/endpoints/test_organization_sentry_app_installation_details.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
)
1010
from sentry.analytics.events.sentry_app_uninstalled import SentryAppUninstalledEvent
1111
from sentry.constants import SentryAppInstallationStatus
12+
from sentry.deletions.tasks.scheduled import run_scheduled_deletions_control
1213
from sentry.models.auditlogentry import AuditLogEntry
14+
from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation
1315
from sentry.sentry_apps.token_exchange.grant_exchanger import GrantExchanger
1416
from sentry.testutils.cases import APITestCase
1517
from sentry.testutils.helpers.analytics import assert_last_analytics_event
@@ -120,6 +122,11 @@ def test_delete_install(self, record: MagicMock) -> None:
120122
),
121123
)
122124

125+
with self.tasks():
126+
run_scheduled_deletions_control()
127+
128+
assert not SentryAppInstallation.objects.filter(id=self.installation2.id).exists()
129+
123130
response_body = json.loads(responses.calls[0].request.body)
124131

125132
assert response_body.get("installation").get("uuid") == self.installation2.uuid

0 commit comments

Comments
 (0)