diff --git a/api/features/feature_lifecycle/services.py b/api/features/feature_lifecycle/services.py index e6efa43443ac..b1d39458098b 100644 --- a/api/features/feature_lifecycle/services.py +++ b/api/features/feature_lifecycle/services.py @@ -2,7 +2,6 @@ from django.db.models.expressions import Case, Exists, OuterRef, Value, When from django.db.models.fields import BooleanField -from django.db.models.functions import Cast from django.db.models.query import QuerySet from django.utils import timezone @@ -42,7 +41,7 @@ def annotate_feature_queryset_with_lifecycle_stage( has_recent_usage=( Exists(features_in_use.filter(pk=OuterRef("pk"))) if features_in_use is not None - else Cast(Value(None), output_field=BooleanField()) + else Value(None, output_field=BooleanField()) ), has_permanent_tag=Exists( Tag.objects.filter(feature=OuterRef("pk"), is_permanent=True), diff --git a/api/features/feature_lifecycle/views.py b/api/features/feature_lifecycle/views.py index 32af6a6a65b7..eccc8edf0a2b 100644 --- a/api/features/feature_lifecycle/views.py +++ b/api/features/feature_lifecycle/views.py @@ -1,6 +1,7 @@ +from collections import Counter + import structlog from common.environments.permissions import VIEW_ENVIRONMENT -from django.db.models import Count from django.shortcuts import get_object_or_404 from drf_spectacular.utils import extend_schema from rest_framework.permissions import IsAuthenticated @@ -44,10 +45,10 @@ def get(self, request: Request, environment_pk: int) -> Response: environment, ) - counts = features.values("lifecycle_stage").annotate(count=Count("pk")) # type: ignore[misc] - summary: dict[LifecycleStage, int] = {stage: 0 for stage in LifecycleStage} - for stage_count in counts: - summary[stage_count["lifecycle_stage"]] = stage_count["count"] + counts = Counter(features.values_list("lifecycle_stage", flat=True)) # type: ignore[misc] + summary: dict[LifecycleStage, int] = { + stage: counts.get(stage, 0) for stage in LifecycleStage + } logger.info( "summarised", diff --git a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md index dabbe68e03a7..4be021e479e4 100644 --- a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md +++ b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md @@ -134,7 +134,7 @@ Attributes: ### `feature_lifecycle.summarised` Logged at `info` from: - - `api/features/feature_lifecycle/views.py:52` + - `api/features/feature_lifecycle/views.py:53` Attributes: - `environment.id`