: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(flags): drop experiment_id from v2 experiment rules (#117682)
Andersda7d1f6bee19
diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.tsindex c4aa69291d24..cfbd05ab68a5 100644--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts@@ -4988,7 +4988,6 @@ describe('the editor a flag opens in', () => {id: 'rule-experiment',rule_type: 'experiment',targeting: { properties: [] },- experiment_id: 12,paused: false,variants: [{ key: 'control', weight: 50, value: false },diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 3d74b5b4ea59..4e2ebc90523a 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -4570,7 +4570,6 @@ export interface FeatureFlagRulesV2PercentageRolloutRuleexport interface FeatureFlagRulesV2ExperimentRule extends FeatureFlagRulesV2RuleBase, FeatureFlagRulesV2RolloutFields {rule_type: 'experiment'- experiment_id: numberpaused: booleanvariants: { key: string; weight: number; value: JsonType }[]holdout?: { id: number; seed: string; exclusion_percentage: number }diff --git a/products/feature_flags/backend/facade/config.py b/products/feature_flags/backend/facade/config.pyindex a0de6edd62ca..925d2ea86121 100644--- a/products/feature_flags/backend/facade/config.py+++ b/products/feature_flags/backend/facade/config.py@@ -13,9 +13,9 @@ A JSON string or boolean never selects a version, and a stored value that is notreader with only a v1 branch checks the format before it touches any v1 key.The v2 DTOs are structural reads of a stored document. They carry the fields later consumers-route on (return type, ordered rule identities and values, experiment identity, and the cohort-and flag targeting predicates) and nothing else. The full v2 schema lives in the contract; do not-grow this module into a second copy of it.+route on (return type, ordered rule identities and values, and the cohort and flag targeting+predicates) and nothing else. The full v2 schema lives in the contract; do not grow this module+into a second copy of it.Deliberately free of Django/DRF imports (same reason as ``facade.filters``): consumer modelmodules import this at module level.@@ -91,7 +91,6 @@ class RuleV2:# The targeting predicates that name a cohort or another flag, as stored.reference_predicates: tuple[Mapping[str, Any], ...] = ()rule_type: RuleType- experiment_id: int | None# None for an experiment rule, whose values sit on its variants.value: FlagValue | None@@ -170,6 +169,5 @@ def _rule_v2(rule: Mapping[str, Any]) -> RuleV2:prop for prop in rule["targeting"]["properties"] if prop.get("type") in _REFERENCE_PREDICATE_TYPES),rule_type=rule_type,- experiment_id=rule["experiment_id"] if rule_type == "experiment" else None,value=None if rule_type == "experiment" else rule["value"],)diff --git a/products/feature_flags/backend/test/test_facade_config.py b/products/feature_flags/backend/test/test_facade_config.pyindex 7e2bd2bdc07b..b47531728059 100644--- a/products/feature_flags/backend/test/test_facade_config.py+++ b/products/feature_flags/backend/test/test_facade_config.py@@ -56,7 +56,6 @@ V2_BOOLEAN_ALL_RULE_TYPES: dict[str, Any] = {"id": "44444444-4444-4444-8444-444444444444","rule_type": "experiment","targeting": {"properties": []},- "experiment_id": 42,"paused": False,"rollout_percentage": 100,"on_rollout_miss": "continue",@@ -135,19 +134,16 @@ class TestParseV2Config:RuleV2(id="11111111-1111-4111-8111-111111111111",rule_type="targeted_release",- experiment_id=None,value=True,),RuleV2(id="22222222-2222-4222-8222-222222222222",rule_type="percentage_rollout",- experiment_id=None,value=True,),RuleV2(id="44444444-4444-4444-8444-444444444444",rule_type="experiment",- experiment_id=42,value=None,),),@@ -162,7 +158,6 @@ class TestParseV2Config:RuleV2(id="55555555-5555-4555-8555-555555555555",rule_type="percentage_rollout",- experiment_id=None,value="compact",),),@@ -196,7 +191,6 @@ class TestParseV2Config:("rules", None, "rules"),("rule_id", 0, "id"),("rule_type", 0, "rule_type"),- ("experiment_id", 2, "experiment_id"),("rule_value", 1, "value"),])diff --git a/products/feature_flags/backend/test/test_facade_config_validation.py b/products/feature_flags/backend/test/test_facade_config_validation.pyindex 5aa3e34115f3..0963c2122b76 100644--- a/products/feature_flags/backend/test/test_facade_config_validation.py+++ b/products/feature_flags/backend/test/test_facade_config_validation.py@@ -344,9 +344,9 @@ INVALID_DOCUMENTS: list[tuple[str, object, list[tuple[str, str]]]] = [),("targeted_with_experiment_fields",- config(targeted(experiment_id=1, variants=[], holdout=None)),+ config(targeted(paused=False, variants=[], holdout=None)),[- ("unknown_field", "filters.rules[0].experiment_id"),+ ("unknown_field", "filters.rules[0].paused"),("unknown_field", "filters.rules[0].variants"),("unknown_field", "filters.rules[0].holdout"),],diff --git a/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.test.tsx b/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.test.tsxindex 73c5c360b0fd..dcb6d36adf82 100644--- a/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.test.tsx+++ b/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.test.tsx@@ -47,4 +47,36 @@ describe('FeatureFlagRulesV2Readonly', () => {expect(container).toHaveTextContent('50%')expect(container).not.toHaveTextContent('seed-must-not-render')})++ it('shows an experiment rule by its variants and paused state', () => {+ const config: FeatureFlagRulesV2Config = {+ ...CONFIG,+ rules: [+ {+ id: 'rule-2',+ rule_type: 'experiment',+ targeting: { properties: [] },+ value: true,+ rollout_percentage: 100,+ on_rollout_miss: 'continue',+ assignment_algorithm: 'sha1_60_v1',+ seed: 'seed-must-not-render',+ paused: true,+ variants: [+ { key: 'control', weight: 50, value: false },+ { key: 'test', weight: 50, value: true },+ ],+ },+ ],+ }+ const { container } = render(+ <Provider>+ <FeatureFlagRulesV2Readonly config={config} />+ </Provider>+ )++ expect(container).toHaveTextContent('Paused')+ expect(container).toHaveTextContent('control')+ expect(container).not.toHaveTextContent('seed-must-not-render')+ })})diff --git a/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.tsx b/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.tsxindex 5056efe803b3..c6329ea6dc5a 100644--- a/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.tsx+++ b/products/feature_flags/frontend/FeatureFlagRulesV2Readonly.tsx@@ -42,14 +42,11 @@ function ValueCell({ rule }: { rule: FeatureFlagRulesV2Rule }): JSX.Element {}return (<div className="flex flex-col gap-1">- <div className="flex items-center gap-1">- <span>Experiment #{rule.experiment_id}</span>- {rule.paused && (- <LemonTag type="warning" size="small">- Paused- </LemonTag>- )}- </div>+ {rule.paused && (+ <LemonTag type="warning" size="small" className="self-start">+ Paused+ </LemonTag>+ )}{rule.variants.map((variant) => (<div key={variant.key} className="flex items-center gap-2 text-xs"><span className="font-mono">{variant.key}</span>