Skip to content

Commit

Permalink
Merge branch 'master' into dw-workflow-run-id
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE authored Jul 16, 2024
2 parents 1436d33 + 343c907 commit fc65f39
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 1,040 deletions.
53 changes: 44 additions & 9 deletions ee/clickhouse/views/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,56 @@ def update(self, instance: Experiment, validated_data: dict, *args: Any, **kwarg
if extra_keys:
raise ValidationError(f"Can't update keys: {', '.join(sorted(extra_keys))} on Experiment")

if "feature_flag_variants" in validated_data.get("parameters", {}):
if len(validated_data["parameters"]["feature_flag_variants"]) != len(feature_flag.variants):
raise ValidationError("Can't update feature_flag_variants on Experiment")

for variant in validated_data["parameters"]["feature_flag_variants"]:
if (
len([ff_variant for ff_variant in feature_flag.variants if ff_variant["key"] == variant["key"]])
!= 1
):
# if an experiment has launched, we cannot edit its variants anymore.
if not instance.is_draft:
if "feature_flag_variants" in validated_data.get("parameters", {}):
if len(validated_data["parameters"]["feature_flag_variants"]) != len(feature_flag.variants):
raise ValidationError("Can't update feature_flag_variants on Experiment")

for variant in validated_data["parameters"]["feature_flag_variants"]:
if (
len([ff_variant for ff_variant in feature_flag.variants if ff_variant["key"] == variant["key"]])
!= 1
):
raise ValidationError("Can't update feature_flag_variants on Experiment")

properties = validated_data.get("filters", {}).get("properties")
if properties:
raise ValidationError("Experiments do not support global filter properties")

if instance.is_draft:
# if feature flag variants have changed, update the feature flag.
if validated_data.get("parameters"):
variants = validated_data["parameters"].get("feature_flag_variants", [])
aggregation_group_type_index = validated_data["parameters"].get("aggregation_group_type_index")

global_filters = validated_data.get("filters")
properties = []
if global_filters:
properties = global_filters.get("properties", [])
if properties:
raise ValidationError("Experiments do not support global filter properties")

default_variants = [
{"key": "control", "name": "Control Group", "rollout_percentage": 50},
{"key": "test", "name": "Test Variant", "rollout_percentage": 50},
]

filters = {
"groups": [{"properties": properties, "rollout_percentage": 100}],
"multivariate": {"variants": variants or default_variants},
"aggregation_group_type_index": aggregation_group_type_index,
}

existing_flag_serializer = FeatureFlagSerializer(
feature_flag,
data={"filters": filters},
partial=True,
context=self.context,
)
existing_flag_serializer.is_valid(raise_exception=True)
existing_flag_serializer.save()

if instance.is_draft and has_start_date:
feature_flag.active = True
feature_flag.save()
Expand Down
Loading

0 comments on commit fc65f39

Please sign in to comment.