From 3b02c587f5837cb020c9a6f418d643bc72459c36 Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Wed, 1 Nov 2023 13:19:21 -0600 Subject: [PATCH] Order alert groups by -started_at in internal API (#3240) # What this PR does Order alert groups in API by -started_at instead of -pk. This should result in no visible change for most installations. In the case where alert groups are being moved/restored between installations this allows for the display order to be as expected without relying on insertion order. Note: Public API is already using -started_at instead of pk and it is already indexed. ## 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/api/views/alert_group.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9311a63..380561f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Prevent additional polling on Incidents if the previous request didn't complete ([#3205](https://github.com/grafana/oncall/pull/3205)) - Order results from `GET /teams` internal API endpoint by ascending name by @joeyorlando ([#3220](https://github.com/grafana/oncall/pull/3220)) +- Order alert groups internal API endpoint by descending started_at by @mderynck ([#3240](https://github.com/grafana/oncall/pull/3240)) ### Fixed diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 97ef641e..f1db153a 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -423,7 +423,7 @@ class AlertGroupView( # enrich alert groups with select_related and prefetch_related alert_group_pks = [alert_group.pk for alert_group in alert_groups] - queryset = AlertGroup.objects.filter(pk__in=alert_group_pks).order_by("-pk") + queryset = AlertGroup.objects.filter(pk__in=alert_group_pks).order_by("-started_at") queryset = self.get_serializer_class().setup_eager_loading(queryset) alert_groups = list(queryset)