: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
fix(feature-flags): preserve multivariate shape when syncing from API (#60146)
Paul D'Ambra09f77b24ecd2
diff --git a/posthog/management/commands/sync_feature_flags_from_api.py b/posthog/management/commands/sync_feature_flags_from_api.pyindex 77dde00246e5..48abbfa2f410 100644--- a/posthog/management/commands/sync_feature_flags_from_api.py+++ b/posthog/management/commands/sync_feature_flags_from_api.py@@ -9,6 +9,17 @@ from posthog.models import FeatureFlag, Project, Userfrom posthog.ph_client import PH_US_API_KEY+def _build_filters(flag_data: dict) -> dict:+ # /flags?v=2 only exposes the single variant the distinct_id evaluated to,+ # so for multivariate flags we seed with that one variant at 100% and let+ # the user fill in the rest — better than silently dropping to boolean.+ variant = flag_data.get("variant")+ base: dict = {"groups": [{"properties": [], "rollout_percentage": 100}], "payloads": {}}+ if variant:+ base["multivariate"] = {"variants": [{"key": variant, "name": variant, "rollout_percentage": 100}]}+ return base++def sync_feature_flags_from_api(distinct_id: str,groups: dict[str, str] | None = None,@@ -87,7 +98,7 @@ def sync_feature_flags_from_api(key=flag_key,created_by=first_user,active=True,- filters={"groups": [{"properties": [], "rollout_percentage": 100}], "payloads": {}},+ filters=_build_filters(flag_data),)output_fn(f"Created feature flag '{flag_key}'")created_count += 1