Skip to content

Commit

Permalink
ref: match signature of Model.delete (#74955)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored and Christinarlong committed Jul 26, 2024
1 parent 9de7d79 commit 4521bbb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/sentry/models/apiapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class Meta:
def __str__(self):
return self.name

def delete(self, **kwargs):
def delete(self, *args, **kwargs):
with outbox_context(transaction.atomic(router.db_for_write(ApiApplication)), flush=False):
for outbox in self.outboxes_for_update():
outbox.save()
return super().delete(**kwargs)
return super().delete(*args, **kwargs)

def outboxes_for_update(self) -> list[ControlOutbox]:
return [
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/integrations/external_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Meta:
),
]

def delete(self, **kwargs):
def delete(self, *args, **kwargs):
from sentry.integrations.services.integration import integration_service

# TODO: Extract this out of the delete method into the endpoint / controller instead.
Expand All @@ -77,7 +77,7 @@ def delete(self, **kwargs):
team_id=team.id, provider=ExternalProviders(self.provider)
)

return super().delete(**kwargs)
return super().delete(*args, **kwargs)

def handle_async_replication(self, shard_identifier: int) -> None:
from sentry.notifications.services.serial import serialize_external_actor
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/integrations/sentry_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ def outboxes_for_update(self) -> list[ControlOutbox]:
for region_name in find_all_region_names()
]

def delete(self):
def delete(self, *args, **kwargs):
from sentry.models.avatars.sentry_app_avatar import SentryAppAvatar

with outbox_context(transaction.atomic(using=router.db_for_write(SentryApp))):
for outbox in self.outboxes_for_update():
outbox.save()

SentryAppAvatar.objects.filter(sentry_app=self).delete()
return super().delete()
return super().delete(*args, **kwargs)

def _disable(self):
self.events = []
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ def save(self, *args, **kwargs):
def reserve_snowflake_id(cls):
return generate_snowflake_id(cls.snowflake_redis_key)

def delete(self, **kwargs):
def delete(self, *args, **kwargs):
if self.is_default:
raise Exception("You cannot delete the default organization.")
return super().delete(**kwargs)
return super().delete(*args, **kwargs)

def handle_async_replication(self, shard_identifier: int) -> None:
from sentry.hybridcloud.services.organization_mapping.serial import (
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,13 @@ def outbox_for_update(project_identifier: int, organization_identifier: int) ->
object_identifier=project_identifier,
)

def delete(self, **kwargs):
def delete(self, *args, **kwargs):
# There is no foreign key relationship so we have to manually cascade.
notifications_service.remove_notification_settings_for_project(project_id=self.id)

with outbox_context(transaction.atomic(router.db_for_write(Project))):
Project.outbox_for_update(self.id, self.organization_id).save()
return super().delete(**kwargs)
return super().delete(*args, **kwargs)

def normalize_before_relocation_import(
self, pk_map: PrimaryKeyMap, scope: ImportScope, flags: ImportFlags
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Meta:
def class_name(self):
return "User"

def delete(self):
def delete(self, *args, **kwargs):
if self.username == "sentry":
raise Exception('You cannot delete the "sentry" user as it is required by Sentry.')
with outbox_context(transaction.atomic(using=router.db_for_write(User))):
Expand All @@ -207,7 +207,7 @@ def delete(self):
avatar.delete()
for outbox in self.outboxes_for_update(is_user_delete=True):
outbox.save()
return super().delete()
return super().delete(*args, **kwargs)

def update(self, *args, **kwds):
with outbox_context(transaction.atomic(using=router.db_for_write(User))):
Expand Down

0 comments on commit 4521bbb

Please sign in to comment.