: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(flags): use evaluate_flags in python snippet (#69091)
Phill1323a35252a6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 7b4e0430d12c..5f7b9dc91deb 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5975,9 +5975,9 @@ snapshots:scenes-app-feature-flags-code-examples--code-instructions-overview--light:hash: v1.k794b7964.181fee2de309458241649ba0b7b64c8ba9e3dd1b92e23afc08fb9f7922fd50b4.JCNNjcMuzmrKK8oh11XjLWJI5JB43gml6OImSTtV0OAscenes-app-feature-flags-code-examples--code-instructions-python-with-local-evaluation--dark:- hash: v1.k794b7964.46946f802bff06024f069e04ba61b1eb4f07b9692c347b062c5d0f1bc552876e.Ee2U7zY4Myf4PCjHB6vA8AHz25ShhvMqI-D8ldktjaE+ hash: v1.k794b7964.ae82e0deaa34c7ed40c69c8970c41f49e39f214f8d561195b88eb1ee568a5b64.2RiZwm6EtAf04-GExngtPt9VGyCe77N0QWpFWEVssoEscenes-app-feature-flags-code-examples--code-instructions-python-with-local-evaluation--light:- hash: v1.k794b7964.149de39d149c0edda501ec6ba47d15735ac17a767feef1dad874534a55c635fd.4vj3WfZXxE-BSohhgh1FwBdgE31_5RRws0aJiXRcnoA+ hash: v1.k794b7964.38588818dde5174e7dee4d5921b4b5f0f1c0ea09284b224ac6fb42ae46945818.CiDEgwKNzWdBDkYVs8ZP9QH6c8sBcr__0K-kWaeNGfQscenes-app-feature-flags-code-examples--code-instructions-react-native-with-bootstrap--dark:hash: v1.k794b7964.3440d2db4a0a5ab4057d5fe610e30285f872fd1d29ee7033885ab630e5e19865.5XAr0iN2N5213U-PObvEbro61694r_CdMq6g_2zkSRcscenes-app-feature-flags-code-examples--code-instructions-react-native-with-bootstrap--light:@@ -6245,7 +6245,7 @@ snapshots:scenes-app-inbox-scene--self-driving-paused--dark:hash: v1.k794b7964.00929b96e59e35796acfc2f8d5f9f48e148c499b2932c227e1a4cf02c488bde0.0kZ4s9sfw8uPHzO2KT7GZ6vL6y-2qA4qzRoZW7n-bcUscenes-app-inbox-scene--self-driving-paused--light:- hash: v1.k794b7964.e2ed5feaafcc219cbecaedafed11618a60e0b39911f54121ae02acbf68270238.v1MEVslQu-332g2PB_trr6JIb-knUHeoA42roLiGQRI+ hash: v1.k794b7964.3801adf5236e9dcea0f1fa5eeffddd6826efb30725b70760369e486db3567e82.UPOnHRPFkJ4uMMemIpHngMRSjylkumiXVWPnADLiBF4scenes-app-inbox-tabs--pull-requests--dark:hash: v1.k794b7964.dad4d6e7b9f1f68f8eaf4b31187c798dfab1631bb6bf20432ce9746f7df1de73.cqSvLKv0E6PFhnMnbn4FS6yIypKYMUKzoKniwrRI4WMscenes-app-inbox-tabs--pull-requests--light:diff --git a/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx b/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsxindex 637107521c99..eae82f48d0be 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx@@ -327,8 +327,7 @@ export function PythonSnippet({encryptedPayload,samplePropertyName,}: FeatureFlagSnippet): JSX.Element {- const clientSuffix = 'posthog.'- const flagFunction = payload ? 'get_feature_flag_payload' : multivariant ? 'get_feature_flag' : 'feature_enabled'+ const snapshotMethod = payload ? 'get_flag_payload' : multivariant ? 'get_flag' : 'is_enabled'const propertyName = samplePropertyName || 'is_authorized'@@ -350,25 +349,23 @@ remote_config_payload = posthog.get_remote_config_payload('${flagKey}')`}? `# add group properties used in the flag to ensure the flag# is evaluated locally, vs. going to our servers- group_properties={ ${groupType.group_type}: {'${propertyName}': 'value', 'name': 'xyz'}}`+ group_properties={ '${groupType.group_type}': {'${propertyName}': 'value', 'name': 'xyz'}}`: `# add person properties used in the flag to ensure the flag# is evaluated locally, vs. going to our serversperson_properties={'${propertyName}': 'value'}`: ''- const flagSnippet = groupType- ? `${clientSuffix}${flagFunction}(- '${flagKey}',+ const evaluateSnippet = groupType+ ? `posthog.evaluate_flags('user distinct id',groups={ '${groupType.group_type}': '<${groupType.name_singular || 'group'} ID>' },${localEvalAddition})`: localEvalAddition- ? `${clientSuffix}${flagFunction}(- '${flagKey}',+ ? `posthog.evaluate_flags('user distinct id',${localEvalAddition})`- : `${clientSuffix}${flagFunction}('${flagKey}', 'user distinct id')`+ : `posthog.evaluate_flags('user distinct id')`const variableName = payload ? 'matched_flag_payload' : multivariant ? 'enabled_variant' : 'is_my_flag_enabled'const conditional = multivariant ? `${variableName} == 'example-variant'` : `${variableName}`@@ -381,10 +378,14 @@ if ${conditional}:# Do something differently for this ${groupType ? groupType.name_singular || 'group' : 'user'}`+ const reminderPrefix = localEvaluation ? '# ' + LOCAL_EVAL_REMINDER : ''+return (<><CodeSnippet language={Language.Python} wrap>- {`${localEvaluation ? '# ' + LOCAL_EVAL_REMINDER : ''}${variableName} = ${flagSnippet}${followUpCode}`}+ {`${reminderPrefix}flags = ${evaluateSnippet}++${variableName} = flags.${snapshotMethod}('${flagKey}')${followUpCode}`}</CodeSnippet></>)