Skip to content

Commit 9275a83

Browse files
wip model unions
1 parent 94e956b commit 9275a83

File tree

7 files changed

+60
-15
lines changed

7 files changed

+60
-15
lines changed

src/sentry/deletions/defaults/group.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,32 @@
1313
# Group models that relate only to groups and not to events. We assume those to
1414
# be safe to delete/mutate within a single transaction for user-triggered
1515
# actions (delete/reprocess/merge/unmerge)
16-
DIRECT_GROUP_RELATED_MODELS = (
16+
DIRECT_GROUP_RELATED_MODELS: tuple[
17+
type[
18+
models.GroupHash
19+
| models.GroupAssignee
20+
| models.GroupCommitResolution
21+
| models.GroupLink
22+
| models.GroupHistory
23+
| models.GroupBookmark
24+
| models.GroupMeta
25+
| models.GroupEnvironment
26+
| models.GroupRelease
27+
| models.GroupRedirect
28+
| models.GroupResolution
29+
| models.GroupRuleStatus
30+
| models.GroupSeen
31+
| models.GroupShare
32+
| models.GroupSnooze
33+
| models.GroupInbox
34+
| models.GroupOwner
35+
| models.GroupEmailThread
36+
| models.GroupSubscription
37+
| models.GroupHistory
38+
| RuleFireHistory
39+
],
40+
...,
41+
] = (
1742
# prioritize GroupHash
1843
models.GroupHash,
1944
models.GroupAssignee,

src/sentry/models/project.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,9 @@ def transfer_to(self, organization):
506506
# to this however, such as rules, which should maintain their
507507
# configuration when moved across organizations.
508508
if org_changed:
509-
for model in ReleaseProject, ReleaseProjectEnvironment, EnvironmentProject:
510-
model.objects.filter(project_id=self.id).delete()
509+
ReleaseProject.objects.filter(project_id=self.id).delete()
510+
ReleaseProjectEnvironment.objects.filter(project_id=self.id).delete()
511+
EnvironmentProject.objects.filter(project_id=self.id).delete()
511512
# this is getting really gross, but make sure there aren't lingering associations
512513
# with old orgs or teams
513514
ProjectTeam.objects.filter(project=self, team__organization_id=old_org_id).delete()

src/sentry/models/release.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,18 @@ def merge(cls, to_release, from_releases):
514514
from sentry.models.releaseprojectenvironment import ReleaseProjectEnvironment
515515
from sentry.models.releases.release_project import ReleaseProject
516516

517-
model_list = (
517+
model_list: tuple[
518+
type[
519+
ReleaseCommit
520+
| ReleaseEnvironment
521+
| ReleaseFile
522+
| ReleaseProject
523+
| ReleaseProjectEnvironment
524+
| GroupRelease
525+
| GroupResolution
526+
],
527+
...,
528+
] = (
518529
ReleaseCommit,
519530
ReleaseEnvironment,
520531
ReleaseFile,

src/sentry/models/user.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ def merge_to(from_user: User, to_user: User) -> None:
377377
# While it would be nice to make the following changes in a transaction, there are too many
378378
# unique constraints to make this feasible. Instead, we just do it sequentially and ignore
379379
# the `IntegrityError`s.
380-
user_related_models: tuple[type[Model], ...] = (
380+
user_related_models: tuple[
381+
type[Authenticator | Identity | UserAvatar | UserEmail | UserOption], ...
382+
] = (
381383
Authenticator,
382384
Identity,
383385
UserAvatar,

src/sentry/reprocessing2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@
119119
# 1. they are migrated as part of the processing pipeline (post-process/save-event)
120120
# 2. there are a lot of them per group. For remaining events, we need to chunk
121121
# up those queries for them to not get too slow
122-
EVENT_MODELS_TO_MIGRATE = (EventAttachment, models.UserReport)
122+
EVENT_MODELS_TO_MIGRATE: tuple[type[EventAttachment | models.UserReport], ...] = (
123+
EventAttachment,
124+
models.UserReport,
125+
)
123126

124127
# The amount of seconds after which we assume there was no progress during reprocessing,
125128
# and after which we just give up and mark the group as finished.

src/sentry/runner/commands/cleanup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,11 @@ def is_filtered(model: type[Model]) -> bool:
248248
expired_threshold = timezone.now() - timedelta(days=days)
249249
models.OrganizationMember.objects.delete_expired(expired_threshold)
250250

251-
for model_tp in [models.ApiGrant, models.ApiToken]:
251+
expires_models: tuple[type[models.ApiGrant | models.ApiToken], ...] = (
252+
models.ApiGrant,
253+
models.ApiToken,
254+
)
255+
for model_tp in expires_models:
252256
debug_output(f"Removing expired values for {model_tp.__name__}")
253257

254258
if is_filtered(model_tp):
@@ -273,8 +277,8 @@ def is_filtered(model: type[Model]) -> bool:
273277
if is_filtered(ExportedData):
274278
debug_output(">> Skipping ExportedData files")
275279
else:
276-
queryset = ExportedData.objects.filter(date_expired__lt=(timezone.now()))
277-
for item in queryset:
280+
export_data_queryset = ExportedData.objects.filter(date_expired__lt=(timezone.now()))
281+
for item in export_data_queryset:
278282
item.delete_file()
279283

280284
project_id = None

src/sentry/testutils/helpers/backups.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,11 @@ def create_exhaustive_organization(
610610
user_id=owner_id,
611611
type=1,
612612
)
613-
for group_model in {GroupAssignee, GroupBookmark, GroupSeen, GroupShare, GroupSubscription}:
614-
group_model.objects.create(
615-
project=project,
616-
group=group,
617-
user_id=owner_id,
618-
)
613+
GroupAssignee.objects.create(project=project, group=group, user_id=owner_id)
614+
GroupBookmark.objects.create(project=project, group=group, user_id=owner_id)
615+
GroupSeen.objects.create(project=project, group=group, user_id=owner_id)
616+
GroupShare.objects.create(project=project, group=group, user_id=owner_id)
617+
GroupSubscription.objects.create(project=project, group=group, user_id=owner_id)
619618

620619
return org
621620

0 commit comments

Comments
 (0)