From 765b12a8c049ec65956707c0ab5792376d5dee47 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 5 Jun 2024 23:24:25 +0100 Subject: [PATCH] fix(versioning): send live from when creating versions for change requests (#4116) --- api/features/workflows/core/models.py | 4 ++-- frontend/common/services/useFeatureVersion.ts | 3 ++- frontend/common/stores/feature-list-store.ts | 1 + frontend/common/types/requests.ts | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/features/workflows/core/models.py b/api/features/workflows/core/models.py index 9867197d9f22..83cfb5e4d33e 100644 --- a/api/features/workflows/core/models.py +++ b/api/features/workflows/core/models.py @@ -250,14 +250,14 @@ def prevent_change_request_delete_if_committed(self) -> None: # feature states, we also want to prevent it at the ORM level. if self.committed_at and not ( self.environment.deleted_at - or (self._live_from and self._live_from > timezone.now()) + or (self.live_from and self.live_from > timezone.now()) ): raise ChangeRequestDeletionError( "Cannot delete a Change Request that has been committed." ) @property - def _live_from(self) -> datetime | None: + def live_from(self) -> datetime | None: # First we check if there are feature states associated with the change request # and, if so, we return the live_from of the feature state with the earliest # live_from. diff --git a/frontend/common/services/useFeatureVersion.ts b/frontend/common/services/useFeatureVersion.ts index 09debab7d5ea..f389d6ce09ab 100644 --- a/frontend/common/services/useFeatureVersion.ts +++ b/frontend/common/services/useFeatureVersion.ts @@ -27,6 +27,7 @@ export const featureVersionService = service await createFeatureVersion(getStore(), { environmentId: query.environmentId, featureId: query.featureId, + liveFrom: query.liveFrom, }) // Step 2: Get the feature states for the live version @@ -161,7 +162,7 @@ export const featureVersionService = service >({ invalidatesTags: [{ id: 'LIST', type: 'FeatureVersion' }], query: (query: Req['createFeatureVersion']) => ({ - body: {}, + body: { live_from: query.liveFrom }, method: 'POST', url: `environments/${query.environmentId}/features/${query.featureId}/versions/`, }), diff --git a/frontend/common/stores/feature-list-store.ts b/frontend/common/stores/feature-list-store.ts index f3b946607000..398952fcb16d 100644 --- a/frontend/common/stores/feature-list-store.ts +++ b/frontend/common/stores/feature-list-store.ts @@ -482,6 +482,7 @@ const controller = { featureId: projectFlag.id, featureStates, skipPublish: true, + liveFrom: changeRequest.live_from, }) environment_feature_versions = [version.version_sha] } diff --git a/frontend/common/types/requests.ts b/frontend/common/types/requests.ts index 446913279932..612d468b6c94 100644 --- a/frontend/common/types/requests.ts +++ b/frontend/common/types/requests.ts @@ -311,10 +311,12 @@ export type Req = { | 'toRemove' | 'multivariate_feature_state_values' >[] + liveFrom?: string } createFeatureVersion: { environmentId: number featureId: number + liveFrom?: string } publishFeatureVersion: { sha: string