From 33c5e892994530c10dcf6ce62091ed0e174d4bcd Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Thu, 3 Aug 2023 11:11:52 +0200 Subject: [PATCH] remove unused dynamic settings (#2735) # What this PR does While working on https://github.com/grafana/oncall/pull/2734 I removed a block of code that was the last reference to a dynamic setting (`enabled_web_schedules_orgs`). That led me to see which dynamic settings we still have references to (at the database level), and create this cleanup migration for deprecated dynamic settings. ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- .../0005_drop_unused_dynamic_settings.py | 42 +++++++++++++++++++ .../apps/slack/slack_client/slack_client.py | 12 ------ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 engine/apps/base/migrations/0005_drop_unused_dynamic_settings.py diff --git a/engine/apps/base/migrations/0005_drop_unused_dynamic_settings.py b/engine/apps/base/migrations/0005_drop_unused_dynamic_settings.py new file mode 100644 index 00000000..ac31d56c --- /dev/null +++ b/engine/apps/base/migrations/0005_drop_unused_dynamic_settings.py @@ -0,0 +1,42 @@ +# Generated by Django 3.2.20 on 2023-08-02 17:56 + +from django.db import migrations + + +def remove_unused_dynamic_settings(apps, schema_editor): + """ + These are deprecated dynamic settings that no longer have references and should be dropped + """ + DynamicSetting = apps.get_model("base", "DynamicSetting") + + DynamicSetting.objects.filter( + name__in=[ + "enabled_web_schedules_orgs", + "enabled_mobile_test_push", + "enabled_webhooks_2_orgs", + "org_id_to_enable_insight_logs", + "messaging_backends_enabled_orgs", + "mobile_app_settings", + "is_grafana_integration_enabled", + "skip_web_cache_for_alert_group", + "postpone_distribute_alert", + "async_alert_creation", + "postpone_distribute_alert_task", + "postpone_create_alert_task", + "simulate_slack_downtime", + "skip_invalidate_web_cache_for_alert_group", + "enabled_final_schedule_export", + "self_hosted_invitations", + ] + ).delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ("base", "0004_auto_20230616_1510"), + ] + + operations = [ + migrations.RunPython(remove_unused_dynamic_settings, migrations.RunPython.noop), + ] diff --git a/engine/apps/slack/slack_client/slack_client.py b/engine/apps/slack/slack_client/slack_client.py index de52c62e..a928c0d6 100644 --- a/engine/apps/slack/slack_client/slack_client.py +++ b/engine/apps/slack/slack_client/slack_client.py @@ -12,7 +12,6 @@ from .exceptions import ( SlackAPIException, SlackAPIRateLimitException, SlackAPITokenException, - SlackClientException, ) from .slack_client_server import SlackClientServer @@ -88,17 +87,6 @@ class SlackClientWithErrorHandling(SlackClient): return cumulative_response, cursor, rate_limited def api_call(self, *args, **kwargs): - from apps.base.models import DynamicSetting - - simulate_slack_downtime = DynamicSetting.objects.get_or_create( - name="simulate_slack_downtime", defaults={"boolean_value": False} - )[0] - - if simulate_slack_downtime.boolean_value: - # When slack is down it returns 503 with no response.text which leads to JSONDecodeError. - # We handle it in SlackClientServer and raise SlackClientException instead - raise SlackClientException("Slack Downtime Simulation") - response = super(SlackClientWithErrorHandling, self).api_call(*args, **kwargs) if not response["ok"]: