Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop application edit after creation #11985

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions experimenter/experimenter/experiments/api/v5/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def validate_name(self, value):

def validate(self, data):
data = super().validate(data)

if self.instance and "application" in data:
raise serializers.ValidationError(
{"application": "Application cannot be updated after creation."}
)

feature_values = data.get("feature_values")

Expand Down Expand Up @@ -894,6 +899,12 @@ def validate_status_next(self, value):
return value

def validate(self, data):

if self.instance and "application" in data and self.instance.application != data["application"]:
raise serializers.ValidationError(
{"application": "Application cannot be updated after creation."}
)

data = super().validate(data)

non_is_archived_fields = set(data.keys()) - set(
Expand Down Expand Up @@ -955,6 +966,11 @@ def validate(self, data):
return data

def update(self, experiment, validated_data):
if "application" in validated_data and experiment.application != validated_data["application"]:
raise serializers.ValidationError(
{"application": "Application cannot be updated after creation."}
)

if (
experiment.is_rollout
and validated_data.get("population_percent") != experiment.population_percent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def test_saves_existing_experiment_with_changelog(self):
)
self.assertEqual(experiment.changes.count(), 1)

data = {
invalid_data = {
"application": NimbusExperiment.Application.DESKTOP,
"hypothesis": "New Hypothesis",
"name": "New Name",
Expand All @@ -310,11 +310,31 @@ def test_saves_existing_experiment_with_changelog(self):
}

serializer = NimbusExperimentSerializer(
experiment, data=data, context={"user": self.user}
experiment, data=invalid_data, context={"user": self.user}
)

self.assertTrue(serializer.is_valid(), serializer.errors)
self.assertFalse(serializer.is_valid())
self.assertIn("application", serializer.errors)
self.assertEqual(
serializer.errors["application"],
["Application cannot be updated after creation."],
)

valid_data = {
"hypothesis": "New Hypothesis",
"name": "New Name",
"public_description": "New public description",
"changelog_message": "test changelog message",
"feature_configs": [feature_config.id],
"prevent_pref_conflicts": True,
}

serializer = NimbusExperimentSerializer(
experiment, data=valid_data, context={"user": self.user}, partial=True
)

self.assertTrue(serializer.is_valid(), serializer.errors)

experiment = serializer.save()
self.assertEqual(experiment.changes.count(), 2)
self.assertEqual(experiment.application, NimbusExperiment.Application.DESKTOP)
Expand Down