Skip to content

Commit

Permalink
Delete the feature segments (which cascade to the feature states) ins…
Browse files Browse the repository at this point in the history
…tead of feature states
  • Loading branch information
matthewelwell committed Jun 3, 2024
1 parent b10d7a7 commit 3dfa2a6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
4 changes: 1 addition & 3 deletions api/features/versioning/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ def _update_feature_state(
def _delete_feature_states(
self, segment_ids: list[int], version: EnvironmentFeatureVersion
) -> None:
version.feature_states.filter(
feature_segment__segment_id__in=segment_ids
).delete()
version.feature_segments.filter(segment_id__in=segment_ids).delete()

def _is_segment_override(self, feature_state: dict) -> bool:
return feature_state.get("feature_segment") is not None
Expand Down
39 changes: 39 additions & 0 deletions api/tests/unit/features/versioning/test_unit_versioning_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,3 +1085,42 @@ def test_create_new_version_for_multivariate_feature(
).multivariate_feature_state_values.all()
]
)


def test_create_new_version_delete_segment_override_updates_overrides_immediately(
feature: Feature,
segment: Segment,
feature_segment: FeatureSegment,
segment_featurestate: FeatureState,
environment_v2_versioning: Environment,
admin_client: APIClient,
) -> None:
# Given
create_version_url = reverse(
"api-v1:versioning:environment-feature-versions-list",
args=[environment_v2_versioning.id, feature.id],
)

data = {
"segment_ids_to_delete_overrides": [segment.id],
"publish_immediately": True,
}

# When
response = admin_client.post(
create_version_url,
data=json.dumps(data),
content_type="application/json",
)

# Then
assert response.status_code == status.HTTP_201_CREATED

get_feature_segments_url = "%s?environment=%d&feature=%d" % (
reverse("api-v1:features:feature-segment-list"),
environment_v2_versioning.id,
feature.id,
)
get_feature_segments_response = admin_client.get(get_feature_segments_url)
assert get_feature_segments_response.status_code == status.HTTP_200_OK
assert get_feature_segments_response.json()["count"] == 0

0 comments on commit 3dfa2a6

Please sign in to comment.