From 53d35d05c3b7451898915c0c73f4350f053b9613 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 8 May 2024 15:25:05 +0100 Subject: [PATCH] Clear environment feature versions --- api/features/versioning/tasks.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/api/features/versioning/tasks.py b/api/features/versioning/tasks.py index 204eb0928dbb..43e0a8b35d49 100644 --- a/api/features/versioning/tasks.py +++ b/api/features/versioning/tasks.py @@ -39,16 +39,24 @@ def enable_v2_versioning(environment_id: int) -> None: def disable_v2_versioning(environment_id: int) -> None: from environments.models import Environment from features.models import FeatureState + from features.versioning.models import EnvironmentFeatureVersion environment = Environment.objects.get(id=environment_id) - queryset = get_environment_flags_queryset(environment) + latest_feature_states = get_environment_flags_queryset(environment) + # delete any feature states associated with older versions FeatureState.objects.filter(identity_id__isnull=True).exclude( - id__in=[fs.id for fs in queryset] + id__in=[fs.id for fs in latest_feature_states] ).delete() - queryset.update(version=1, live_from=timezone.now()) + # update the latest feature states to be the latest version according + # to the old versioning system + latest_feature_states.update( + version=1, live_from=timezone.now(), environment_feature_version=None + ) + + EnvironmentFeatureVersion.objects.filter(environment=environment).delete() environment.use_v2_feature_versioning = False environment.save()