From aef162652e643dbc308e98e8fef92fb1ad2a533c Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Thu, 13 Jul 2023 16:32:30 -0600 Subject: [PATCH] Fix migration for long names and do not include deleted (#2528) --- engine/apps/webhooks/migrations/0008_auto_20230712_1613.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engine/apps/webhooks/migrations/0008_auto_20230712_1613.py b/engine/apps/webhooks/migrations/0008_auto_20230712_1613.py index f31a897b..266d1810 100644 --- a/engine/apps/webhooks/migrations/0008_auto_20230712_1613.py +++ b/engine/apps/webhooks/migrations/0008_auto_20230712_1613.py @@ -16,11 +16,12 @@ def convert_custom_button_to_webhook(apps, schema_editor): Webhooks = apps.get_model("webhooks", "Webhook") EscalationPolicies = apps.get_model("alerts", "EscalationPolicy") - for cb in CustomButton.objects.all(): + # CustomButtonManager isn't used + for cb in CustomButton.objects.filter(deleted_at=None): webhook, _ = Webhooks.objects.get_or_create( organization=cb.organization, team=cb.team, - name=cb.name + LEGACY_SUFFIX, + name=cb.name[:100 - len(LEGACY_SUFFIX)] + LEGACY_SUFFIX, is_legacy=True, defaults=dict( created_at=cb.created_at, @@ -50,7 +51,7 @@ def undo_custom_button_to_webhook(apps, schema_editor): for webhook in Webhooks.objects.filter(is_legacy=True): try: - cb = CustomButton.objects.get(name=webhook.name.removesuffix(LEGACY_SUFFIX), team=webhook.team, organization=webhook.organization) + cb = CustomButton.objects.get(name__startswith=webhook.name.removesuffix(LEGACY_SUFFIX), team=webhook.team, organization=webhook.organization) except ObjectDoesNotExist: logger.warning(f"Did not find matching custom button to revert {webhook.name} {webhook.organization.stack_slug}, skipping") continue