Skip to content

Commit 3d67d3a

Browse files
test(hybrid-cloud): Stabilizes sentry app install tests (#53004)
1 parent f243492 commit 3d67d3a

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/sentry/models/organizationmember.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class Meta:
251251
__org_roles_from_teams = None
252252

253253
def delete(self, *args, **kwds):
254-
with outbox_context(transaction.atomic()):
254+
with outbox_context(transaction.atomic(using=router.db_for_write(OrganizationMember))):
255255
self.save_outbox_for_update()
256256
return super().delete(*args, **kwds)
257257

@@ -587,7 +587,7 @@ def approve_member_invitation(
587587
from sentry import audit_log
588588
from sentry.utils.audit import create_audit_entry_from_user
589589

590-
with transaction.atomic():
590+
with transaction.atomic(using=router.db_for_write(OrganizationMember)):
591591
self.approve_invite()
592592
self.save()
593593

src/sentry/models/user.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.contrib.auth.models import AbstractBaseUser
66
from django.contrib.auth.models import UserManager as DjangoUserManager
77
from django.contrib.auth.signals import user_logged_out
8-
from django.db import IntegrityError, models, transaction
8+
from django.db import IntegrityError, models, router, transaction
99
from django.db.models import Count, Subquery
1010
from django.db.models.query import QuerySet
1111
from django.dispatch import receiver
@@ -162,7 +162,7 @@ def class_name(self):
162162
def delete(self):
163163
if self.username == "sentry":
164164
raise Exception('You cannot delete the "sentry" user as it is required by Sentry.')
165-
with outbox_context(transaction.atomic(), flush=False):
165+
with outbox_context(transaction.atomic(using=router.db_for_write(User)), flush=False):
166166
avatar = self.avatar.first()
167167
if avatar:
168168
avatar.delete()
@@ -171,13 +171,13 @@ def delete(self):
171171
return super().delete()
172172

173173
def update(self, *args, **kwds):
174-
with outbox_context(transaction.atomic(), flush=False):
174+
with outbox_context(transaction.atomic(using=router.db_for_write(User)), flush=False):
175175
for outbox in self.outboxes_for_update():
176176
outbox.save()
177177
return super().update(*args, **kwds)
178178

179179
def save(self, *args, **kwargs):
180-
with outbox_context(transaction.atomic(), flush=False):
180+
with outbox_context(transaction.atomic(using=router.db_for_write(User)), flush=False):
181181
if not self.username:
182182
self.username = self.email
183183
result = super().save(*args, **kwargs)
@@ -323,7 +323,7 @@ def merge_to(from_user, to_user):
323323
for model in model_list:
324324
for obj in model.objects.filter(user_id=from_user.id):
325325
try:
326-
with transaction.atomic():
326+
with transaction.atomic(using=router.db_for_write(User)):
327327
obj.update(user_id=to_user.id)
328328
except IntegrityError:
329329
pass

src/sentry/services/hybrid_cloud/organization/impl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, Iterable, List, Mapping, Optional, Set, Union, cast
44

5-
from django.db import IntegrityError, models, transaction
5+
from django.db import IntegrityError, models, router, transaction
66
from django.dispatch import Signal
77

88
from sentry import roles
@@ -491,7 +491,7 @@ def update_region_user(self, *, user: RpcRegionUser, region_name: str) -> None:
491491
# Normally, calling update on a QS for organization member fails because we need to ensure that updates to
492492
# OrganizationMember objects produces outboxes. In this case, it is safe to do the update directly because
493493
# the attribute we are changing never needs to produce an outbox.
494-
with unguarded_write():
494+
with unguarded_write(using=router.db_for_write(OrganizationMember)):
495495
OrganizationMember.objects.filter(user_id=user.id).update(
496496
user_is_active=user.is_active, user_email=user.email
497497
)

tests/sentry/api/endpoints/test_organization_sentry_app_installation_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def setUp(self):
5656
)
5757

5858

59-
@control_silo_test()
59+
@control_silo_test(stable=True)
6060
class GetSentryAppInstallationDetailsTest(SentryAppInstallationDetailsTest):
6161
def test_access_within_installs_organization(self):
6262
self.login_as(user=self.user)

tests/sentry/deletions/test_sentry_app_installations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sentry.testutils.outbox import outbox_runner
1717

1818

19-
class TestSentryAppIntallationDeletionTask(TestCase):
19+
class TestSentryAppInstallationDeletionTask(TestCase):
2020
def setUp(self):
2121
self.user = self.create_user()
2222
self.org = self.create_organization()

0 commit comments

Comments
 (0)