Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/features/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ def validate_feature(self, feature): # type: ignore[no-untyped-def]
return feature

def validate_environment(self, environment): # type: ignore[no-untyped-def]
if environment is None:
raise serializers.ValidationError("Environment may not be null.")
if self.instance and self.instance.environment_id != environment.id: # type: ignore[union-attr]
raise serializers.ValidationError(
"Cannot change the environment of a feature state"
Expand Down
24 changes: 24 additions & 0 deletions api/tests/unit/features/test_unit_features_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3246,6 +3246,30 @@ def test_update_feature_state__change_feature__returns_400(
)


def test_update_feature_state__null_environment__returns_400(
admin_client_new: APIClient,
environment: Environment,
feature: Feature,
feature_state: FeatureState,
) -> None:
# Given
url = reverse("api-v1:features:featurestates-detail", args=[feature_state.id])
data = {
"enabled": True,
"environment": None,
"feature": feature.id,
}

# When
response = admin_client_new.put(
url, data=json.dumps(data), content_type="application/json"
)

# Then
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert "environment" in response.json()


@pytest.mark.parametrize(
"client",
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")],
Expand Down
Loading