From 8427953fad7e4d9a1bb4cf17173211f92092d35a Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Wed, 31 Jan 2024 11:52:20 -0700 Subject: [PATCH] Fix Incident plugin status sync (#3802) # What this PR does - Handle case where key exists for jsonData but explicitly set to None - Disable incident if plugin disabled after or in the case it was removed completely from the Grafana instance ## Which issue(s) this PR fixes ## 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) --- CHANGELOG.md | 1 + engine/apps/user_management/sync.py | 5 ++++- engine/apps/user_management/tests/test_sync.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e1c2490..666b54a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Address `SlackAPIRatelimitError` exceptions in `apps.slack.tasks.send_message_to_thread_if_bot_not_in_channel` task by @joeyorlando ([#3803](https://github.com/grafana/oncall/pull/3803)) +- Fix exception when parsing incident plugin config @mderynck ([#3802](https://github.com/grafana/oncall/pull/3802)) ## v1.3.96 (2024-01-31) diff --git a/engine/apps/user_management/sync.py b/engine/apps/user_management/sync.py index fd8256e1..df0ce19b 100644 --- a/engine/apps/user_management/sync.py +++ b/engine/apps/user_management/sync.py @@ -111,9 +111,12 @@ def _sync_grafana_incident_plugin(organization: Organization, grafana_api_client It intended to use only inside _sync_organization. It mutates, but not saves org, it's saved in _sync_organization. """ grafana_incident_settings, _ = grafana_api_client.get_grafana_incident_plugin_settings() + organization.is_grafana_incident_enabled = False + organization.grafana_incident_backend_url = None + if grafana_incident_settings is not None: organization.is_grafana_incident_enabled = grafana_incident_settings["enabled"] - organization.grafana_incident_backend_url = grafana_incident_settings.get("jsonData", {}).get( + organization.grafana_incident_backend_url = (grafana_incident_settings.get("jsonData") or {}).get( GrafanaAPIClient.GRAFANA_INCIDENT_PLUGIN_BACKEND_URL_KEY ) diff --git a/engine/apps/user_management/tests/test_sync.py b/engine/apps/user_management/tests/test_sync.py index 158f1378..96a86bae 100644 --- a/engine/apps/user_management/tests/test_sync.py +++ b/engine/apps/user_management/tests/test_sync.py @@ -541,6 +541,7 @@ class TestSyncGrafanaIncidentParams: MOCK_GRAFANA_INCIDENT_BACKEND_URL, ), TestSyncGrafanaIncidentParams(({"enabled": True}, None), True, None), + TestSyncGrafanaIncidentParams(({"enabled": True, "jsonData": None}, None), True, None), # missing jsonData (sometimes this is what we get back from the Grafana API) TestSyncGrafanaIncidentParams(({"enabled": False}, None), False, None), # plugin is disabled for some reason ],