Browse Source

ref: delete migrations which call _delete_from_snuba with incorrect args (#56087)

the signature was changed in c0dc16efc15f62d1ed26624e4a14f181c144b71d
and these migrations cannot succeed




<!-- Describe your PR here. -->
anthony sottile 1 year ago
parent
commit
d40a6b6c2e

+ 0 - 10
pyproject.toml

@@ -548,16 +548,6 @@ module = [
     "sentry.middleware.ratelimit",
     "sentry.middleware.subdomain",
     "sentry.middleware.superuser",
-    "sentry.migrations.0001_squashed_0200_release_indices",
-    "sentry.migrations.0223_semver_backfill_2",
-    "sentry.migrations.0232_backfill_missed_semver_releases",
-    "sentry.migrations.0233_recreate_subscriptions_in_snuba",
-    "sentry.migrations.0237_recreate_subscriptions_in_snuba",
-    "sentry.migrations.0292_migrate_sessions_subs_user_counts",
-    "sentry.migrations.0293_restore_metrics_based_alerts",
-    "sentry.migrations.0314_bit_int_for_org_and_project_id",
-    "sentry.migrations.0407_recreate_perf_alert_subscriptions",
-    "sentry.migrations.0418_add_actor_constraints",
     "sentry.models.artifactbundle",
     "sentry.models.auditlogentry",
     "sentry.models.integrations.external_issue",

+ 2 - 2
src/sentry/migrations/0001_squashed_0200_release_indices.py

@@ -2280,7 +2280,7 @@ class Migration(migrations.Migration):
             options={
                 "db_table": "sentry_project",
             },
-            bases=(models.Model, sentry.db.mixin.PendingDeletionMixin),
+            bases=(models.Model, sentry.db.mixin.PendingDeletionMixin),  # type: ignore  # django-stubs#1708
         ),
         migrations.CreateModel(
             name="ProjectAvatar",
@@ -3077,7 +3077,7 @@ class Migration(migrations.Migration):
             options={
                 "db_table": "sentry_repository",
             },
-            bases=(models.Model, sentry.db.mixin.PendingDeletionMixin),
+            bases=(models.Model, sentry.db.mixin.PendingDeletionMixin),  # type: ignore  # django-stubs#1708
         ),
         migrations.CreateModel(
             name="ReprocessingReport",

+ 0 - 2
src/sentry/migrations/0001_squashed_0484_break_org_member_user_fk.py

@@ -88,11 +88,9 @@ class Migration(CheckedMigration):
         ("sentry", "0230_sentry_app_config_jsonfield"),
         ("sentry", "0231_alert_rule_comparison_delta"),
         ("sentry", "0232_backfill_missed_semver_releases"),
-        ("sentry", "0233_recreate_subscriptions_in_snuba"),
         ("sentry", "0234_grouphistory"),
         ("sentry", "0235_add_metricskeyindexer_table"),
         ("sentry", "0236_remove_legacy_key_transactions"),
-        ("sentry", "0237_recreate_subscriptions_in_snuba"),
         ("sentry", "0238_remove_scheduleddeletion_aborted"),
         ("sentry", "0239_drop_scheduleddeletion_aborted"),
         ("sentry", "0240_grouphistory_index"),

+ 4 - 1
src/sentry/migrations/0223_semver_backfill_2.py

@@ -1,4 +1,7 @@
 # Generated by Django 1.11.29 on 2021-07-15 23:49
+from __future__ import annotations
+
+from typing import Any
 
 from django.db import connection, migrations
 from psycopg2.extras import execute_values
@@ -61,7 +64,7 @@ def backfill_semver(apps, schema_editor):
         result_value_getter=lambda item: item[0],
     )
     cursor = connection.cursor()
-    batch = []
+    batch: list[tuple[Any, ...]] = []
     for pk, version, *semver_fields in queryset:
         try:
             version_info = parse_release(version)

+ 5 - 1
src/sentry/migrations/0232_backfill_missed_semver_releases.py

@@ -1,5 +1,9 @@
 # Generated by Django 2.2.24 on 2021-09-23 14:02
 # Copied from 0223_semver_backfill_2.py
+from __future__ import annotations
+
+from typing import Any
+
 from django.db import connection, migrations
 from psycopg2.extras import execute_values
 from sentry_relay.exceptions import RelayError
@@ -61,7 +65,7 @@ def backfill_semver(apps, schema_editor):
         result_value_getter=lambda item: item[0],
     )
     cursor = connection.cursor()
-    batch = []
+    batch: list[tuple[Any, ...]] = []
     for pk, version, *semver_fields in queryset:
         try:
             version_info = parse_release(version)

+ 0 - 89
src/sentry/migrations/0233_recreate_subscriptions_in_snuba.py

@@ -1,89 +0,0 @@
-# Generated by Django 2.2.24 on 2021-09-24 19:23
-
-import logging
-
-from django.db import migrations
-
-from sentry.snuba.dataset import Dataset
-from sentry.snuba.models import SnubaQueryEventType
-from sentry.snuba.tasks import _create_in_snuba, _delete_from_snuba
-from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
-
-
-def migrate_subscriptions(apps, schema_editor):
-    QuerySubscription = apps.get_model("sentry", "QuerySubscription")
-    AppSnubaQueryEventType = apps.get_model("sentry", "SnubaQueryEventType")
-
-    for subscription in RangeQuerySetWrapperWithProgressBar(
-        QuerySubscription.objects.select_related("snuba_query").all()
-    ):
-        if subscription.subscription_id is not None:
-            # The migration apps don't build this property, so manually set it.
-            raw_event_types = AppSnubaQueryEventType.objects.filter(
-                snuba_query=subscription.snuba_query
-            ).all()
-            event_types = [SnubaQueryEventType.EventType(ev.type) for ev in raw_event_types]
-            setattr(subscription.snuba_query, "event_types", event_types)
-
-            subscription_id = None
-            try:
-                subscription_id = _create_in_snuba(subscription)
-            except Exception as e:
-                logging.exception(f"failed to recreate {subscription.subscription_id}: {e}")
-                continue
-
-            try:
-                _delete_from_snuba(
-                    Dataset(subscription.snuba_query.dataset),
-                    subscription.subscription_id,
-                )
-            except Exception as e:
-                try:
-                    # Delete the subscription we just created to avoid orphans
-                    _delete_from_snuba(
-                        Dataset(subscription.snuba_query.dataset),
-                        subscription_id,
-                    )
-                except Exception as oe:
-                    logging.exception(f"failed to delete orphan {subscription_id}: {oe}")
-
-                logging.exception(f"failed to delete {subscription.subscription_id}: {e}")
-                continue
-
-            QuerySubscription.objects.filter(id=subscription.id).update(
-                subscription_id=subscription_id
-            )
-
-
-class Migration(migrations.Migration):
-    # This flag is used to mark that a migration shouldn't be automatically run in
-    # production. We set this to True for operations that we think are risky and want
-    # someone from ops to run manually and monitor.
-    # General advice is that if in doubt, mark your migration as `is_dangerous`.
-    # Some things you should always mark as dangerous:
-    # - Large data migrations. Typically we want these to be run manually by ops so that
-    #   they can be monitored. Since data migrations will now hold a transaction open
-    #   this is even more important.
-    # - Adding columns to highly active tables, even ones that are NULL.
-    is_dangerous = True
-
-    # This flag is used to decide whether to run this migration in a transaction or not.
-    # By default we prefer to run in a transaction, but for migrations where you want
-    # to `CREATE INDEX CONCURRENTLY` this needs to be set to False. Typically you'll
-    # want to create an index concurrently when adding one to an existing table.
-    # You'll also usually want to set this to `False` if you're writing a data
-    # migration, since we don't want the entire migration to run in one long-running
-    # transaction.
-    atomic = False
-
-    dependencies = [
-        ("sentry", "0232_backfill_missed_semver_releases"),
-    ]
-
-    operations = [
-        migrations.RunPython(
-            migrate_subscriptions,
-            migrations.RunPython.noop,
-            hints={"tables": ["sentry_querysubscription", "sentry_snubaqueryeventtype"]},
-        ),
-    ]

+ 1 - 1
src/sentry/migrations/0234_grouphistory.py

@@ -30,7 +30,7 @@ class Migration(migrations.Migration):
     atomic = True
 
     dependencies = [
-        ("sentry", "0233_recreate_subscriptions_in_snuba"),
+        ("sentry", "0232_backfill_missed_semver_releases"),
     ]
 
     operations = [

+ 0 - 89
src/sentry/migrations/0237_recreate_subscriptions_in_snuba.py

@@ -1,89 +0,0 @@
-# Generated by Django 2.2.24 on 2021-10-12 21:01
-
-import logging
-
-from django.db import migrations
-
-from sentry.snuba.dataset import Dataset
-from sentry.snuba.models import SnubaQueryEventType
-from sentry.snuba.tasks import _create_in_snuba, _delete_from_snuba
-from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
-
-
-def migrate_subscriptions(apps, schema_editor):
-    QuerySubscription = apps.get_model("sentry", "QuerySubscription")
-    AppSnubaQueryEventType = apps.get_model("sentry", "SnubaQueryEventType")
-
-    for subscription in RangeQuerySetWrapperWithProgressBar(
-        QuerySubscription.objects.select_related("snuba_query").all()
-    ):
-        if subscription.subscription_id is not None:
-            # The migration apps don't build this property, so manually set it.
-            raw_event_types = AppSnubaQueryEventType.objects.filter(
-                snuba_query=subscription.snuba_query
-            ).all()
-            event_types = [SnubaQueryEventType.EventType(ev.type) for ev in raw_event_types]
-            setattr(subscription.snuba_query, "event_types", event_types)
-
-            subscription_id = None
-            try:
-                subscription_id = _create_in_snuba(subscription)
-            except Exception as e:
-                logging.exception(f"failed to recreate {subscription.subscription_id}: {e}")
-                continue
-
-            try:
-                _delete_from_snuba(
-                    Dataset(subscription.snuba_query.dataset),
-                    subscription.subscription_id,
-                )
-            except Exception as e:
-                try:
-                    # Delete the subscription we just created to avoid orphans
-                    _delete_from_snuba(
-                        Dataset(subscription.snuba_query.dataset),
-                        subscription_id,
-                    )
-                except Exception as oe:
-                    logging.exception(f"failed to delete orphan {subscription_id}: {oe}")
-
-                logging.exception(f"failed to delete {subscription.subscription_id}: {e}")
-                continue
-
-            QuerySubscription.objects.filter(id=subscription.id).update(
-                subscription_id=subscription_id
-            )
-
-
-class Migration(migrations.Migration):
-    # This flag is used to mark that a migration shouldn't be automatically run in
-    # production. We set this to True for operations that we think are risky and want
-    # someone from ops to run manually and monitor.
-    # General advice is that if in doubt, mark your migration as `is_dangerous`.
-    # Some things you should always mark as dangerous:
-    # - Large data migrations. Typically we want these to be run manually by ops so that
-    #   they can be monitored. Since data migrations will now hold a transaction open
-    #   this is even more important.
-    # - Adding columns to highly active tables, even ones that are NULL.
-    is_dangerous = True
-
-    # This flag is used to decide whether to run this migration in a transaction or not.
-    # By default we prefer to run in a transaction, but for migrations where you want
-    # to `CREATE INDEX CONCURRENTLY` this needs to be set to False. Typically you'll
-    # want to create an index concurrently when adding one to an existing table.
-    # You'll also usually want to set this to `False` if you're writing a data
-    # migration, since we don't want the entire migration to run in one long-running
-    # transaction.
-    atomic = False
-
-    dependencies = [
-        ("sentry", "0236_remove_legacy_key_transactions"),
-    ]
-
-    operations = [
-        migrations.RunPython(
-            migrate_subscriptions,
-            migrations.RunPython.noop,
-            hints={"tables": ["sentry_querysubscription", "sentry_snubaqueryeventtype"]},
-        ),
-    ]

+ 1 - 1
src/sentry/migrations/0238_remove_scheduleddeletion_aborted.py

@@ -25,7 +25,7 @@ class Migration(migrations.Migration):
     atomic = True
 
     dependencies = [
-        ("sentry", "0237_recreate_subscriptions_in_snuba"),
+        ("sentry", "0236_remove_legacy_key_transactions"),
     ]
 
     operations = [

+ 1 - 2
src/sentry/migrations/0292_migrate_sessions_subs_user_counts.py

@@ -57,7 +57,6 @@ def delete_subscription_from_snuba(subscription, query_dataset: Dataset):
     )
 
 
-@property
 def event_types(self):
     return [type.event_type for type in self.snubaqueryeventtype_set.all()]
 
@@ -73,7 +72,7 @@ def update_metrics_subscriptions(apps, schema_editor):
         if old_subscription_id is not None:
             try:
                 # The migration apps don't build this property, so patch it here:
-                subscription.snuba_query.event_types = event_types
+                subscription.snuba_query.event_types = property(event_types)
                 create_subscription_in_snuba(subscription)
                 delete_subscription_from_snuba(subscription, Dataset.Metrics)
             except Exception:

Some files were not shown because too many files changed in this diff