Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(experiments): strip stale feature flag config from parameters (#67766)

Andersebeeed5ae477
diff --git a/products/demo/backend/logic/products/hedgebox/matrix.py b/products/demo/backend/logic/products/hedgebox/matrix.py
index 276456638e52..9d2d607a7973 100644
--- a/products/demo/backend/logic/products/hedgebox/matrix.py
+++ b/products/demo/backend/logic/products/hedgebox/matrix.py
@@ -1155,11 +1155,6 @@ class HedgeboxMatrix(Matrix):
],
metrics_secondary=[],
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 34},
- {"key": "red", "rollout_percentage": 33},
- {"key": "blue", "rollout_percentage": 33},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.35),
"minimum_detectable_effect": 15,
},
@@ -1317,11 +1312,6 @@ class HedgeboxMatrix(Matrix):
new_shared_retention.query["uuid"],
],
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 34},
- {"key": "red", "rollout_percentage": 33},
- {"key": "blue", "rollout_percentage": 33},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.40),
"minimum_detectable_effect": 10,
},
@@ -1373,10 +1363,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=pricing_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 50},
- {"key": "test", "rollout_percentage": 50},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.30),
"minimum_detectable_effect": 10,
},
@@ -1421,10 +1407,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=sharing_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 50},
- {"key": "test", "rollout_percentage": 50},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.25),
"minimum_detectable_effect": 12,
},
@@ -1469,11 +1451,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=upgrade_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 34},
- {"key": "aggressive", "rollout_percentage": 33},
- {"key": "subtle", "rollout_percentage": 33},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.35),
"minimum_detectable_effect": 15,
},
@@ -1516,10 +1493,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=retention_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 50},
- {"key": "test", "rollout_percentage": 50},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.30),
"minimum_detectable_effect": 10,
},
@@ -1562,10 +1535,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=team_collab_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 50},
- {"key": "test", "rollout_percentage": 50},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.30),
"minimum_detectable_effect": 12,
},
@@ -1612,10 +1581,6 @@ class HedgeboxMatrix(Matrix):
metrics_secondary=[],
primary_metrics_ordered_uuids=bias_warning_metric_uuids,
parameters={
- "feature_flag_variants": [
- {"key": "control", "rollout_percentage": 90},
- {"key": "test", "rollout_percentage": 10},
- ],
"recommended_sample_size": int(len(self.clusters) * 0.30),
"minimum_detectable_effect": 10,
},
diff --git a/products/experiments/backend/migrations/0026_strip_feature_flag_config_from_parameters.py b/products/experiments/backend/migrations/0026_strip_feature_flag_config_from_parameters.py
new file mode 100644
index 000000000000..b89ba5aac14f
--- /dev/null
+++ b/products/experiments/backend/migrations/0026_strip_feature_flag_config_from_parameters.py
@@ -0,0 +1,50 @@
+from django.db import migrations
+from django.db.models import Q
+
+BATCH_SIZE = 1000
+
+# Feature-flag config now lives only on the linked FeatureFlag (the source of truth) and is
+# projected into the deprecated `parameters` API field at read time. Strip these now-dead keys from
+# existing rows' `parameters` blob. Re-running is a no-op once a row has none of the keys.
+# Frozen copy of ExperimentService.FEATURE_FLAG_CONFIG_KEYS — migrations don't import app code.
+FEATURE_FLAG_CONFIG_KEYS = (
+ "feature_flag_variants",
+ "rollout_percentage",
+ "aggregation_group_type_index",
+ "feature_flag_payloads",
+ "ensure_experience_continuity",
+)
+
+
+def strip_feature_flag_config(apps, schema_editor):
+ Experiment = apps.get_model("experiments", "Experiment")
+
+ key_filter = Q()
+ for key in FEATURE_FLAG_CONFIG_KEYS:
+ key_filter |= Q(parameters__has_key=key)
+ experiment_ids = list(Experiment.objects.filter(key_filter).values_list("id", flat=True).order_by("id"))
+
+ for start in range(0, len(experiment_ids), BATCH_SIZE):
+ batch_ids = experiment_ids[start : start + BATCH_SIZE]
+ to_update = []
+ for experiment in Experiment.objects.filter(id__in=batch_ids).only("id", "parameters"):
+ parameters = experiment.parameters
+ # jsonb `?` also matches string elements of arrays, so the filter can pass non-dicts
+ if not parameters or not isinstance(parameters, dict):
+ continue
+ stripped = {k: v for k, v in parameters.items() if k not in FEATURE_FLAG_CONFIG_KEYS}
+ if stripped != parameters:
+ experiment.parameters = stripped
+ to_update.append(experiment)
+ if to_update:
+ Experiment.objects.bulk_update(to_update, ["parameters"], batch_size=BATCH_SIZE)
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("experiments", "0025_remove_teamexperimentsconfig_funnel_steps_data_disabled"),
+ ]
+
+ operations = [
+ migrations.RunPython(strip_feature_flag_config, migrations.RunPython.noop),
+ ]
diff --git a/products/experiments/backend/migrations/max_migration.txt b/products/experiments/backend/migrations/max_migration.txt
index 53c2907297ba..da9d804e5dbf 100644
--- a/products/experiments/backend/migrations/max_migration.txt
+++ b/products/experiments/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0025_remove_teamexperimentsconfig_funnel_steps_data_disabled
+0026_strip_feature_flag_config_from_parameters