Skip to content

Commit f086416

Browse files
authored
fix(integrations): Fix incorrect organization for external issues (#48050)
Context: [WOR-2860](https://getsentry.atlassian.net/browse/WOR-2860) A project transfer led to missing JIRA-linked issues. This migration should change the organization_id for these issues to the correct org. I'll add some logging around this as a followup to investigate why/how this happened and catch it in the future. [WOR-2860]: https://getsentry.atlassian.net/browse/WOR-2860?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 9860ab2 commit f086416

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
66
will then be regenerated, and you should be able to merge without conflicts.
77

88
nodestore: 0002_nodestore_no_dictfield
9-
sentry: 0428_backfill_denormalize_notification_actor
9+
sentry: 0429_fix_broken_external_issues
1010
social_auth: 0001_initial
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Generated by Django 2.2.28 on 2023-04-25 23:51
2+
3+
from django.db import migrations
4+
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
7+
8+
def fix_broken_external_issues(apps, schema_editor):
9+
ExternalIssue = apps.get_model("sentry", "ExternalIssue")
10+
11+
# Broken issues from redash: https://redash.getsentry.net/queries/4012/source
12+
broken_ids = [636683, 636687, 636692]
13+
old_organization_id = 443715
14+
new_organization_id = 5417824
15+
for issue in ExternalIssue.objects.filter(
16+
id__in=broken_ids, organization_id=old_organization_id
17+
):
18+
issue.organization_id = new_organization_id
19+
issue.save()
20+
21+
22+
class Migration(CheckedMigration):
23+
# This flag is used to mark that a migration shouldn't be automatically run in production. For
24+
# the most part, this should only be used for operations where it's safe to run the migration
25+
# after your code has deployed. So this should not be used for most operations that alter the
26+
# schema of a table.
27+
# Here are some things that make sense to mark as dangerous:
28+
# - Large data migrations. Typically we want these to be run manually by ops so that they can
29+
# be monitored and not block the deploy for a long period of time while they run.
30+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
31+
# have ops run this and not block the deploy. Note that while adding an index is a schema
32+
# change, it's completely safe to run the operation after the code has deployed.
33+
is_dangerous = False
34+
35+
dependencies = [
36+
("sentry", "0428_backfill_denormalize_notification_actor"),
37+
]
38+
39+
operations = [
40+
migrations.RunPython(
41+
fix_broken_external_issues,
42+
reverse_code=migrations.RunPython.noop,
43+
hints={"tables": ["sentry_externalissue"]},
44+
),
45+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sentry.models.integrations.external_issue import ExternalIssue
2+
from sentry.testutils.cases import TestMigrations
3+
4+
5+
class FixBrokenExternalIssues(TestMigrations):
6+
migrate_from = "0428_backfill_denormalize_notification_actor"
7+
migrate_to = "0429_fix_broken_external_issues"
8+
9+
def setup_initial_state(self):
10+
self.valid_external_issue = ExternalIssue.objects.create(
11+
organization_id=5417824, integration_id=1
12+
)
13+
self.broken_external_issue = ExternalIssue.objects.create(
14+
id=636683, organization_id=443715, integration_id=2
15+
)
16+
17+
def test(self):
18+
self.broken_external_issue.refresh_from_db()
19+
self.valid_external_issue.refresh_from_db()
20+
assert self.broken_external_issue.organization_id == 5417824
21+
assert self.valid_external_issue.organization_id == 5417824

0 commit comments

Comments
 (0)