: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): allow dots and slashes in variant keys in the UI (#72995)
Patriciobdc135452814
diff --git a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsxindex 5bc425b7c320..9fb5d31c8f6d 100644--- a/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx+++ b/frontend/src/scenes/experiments/ExperimentView/ExperimentReplayTab.tsx@@ -24,9 +24,9 @@ import { EXPOSURE_UNLINKABLE_REASON, METRIC_UNLINKABLE_REASON } from '../viewRecimport { experimentReplayTabLogic } from './experimentReplayTabLogic'import { VariantTag } from './VariantTag'-// LemonSegmentedButton values must be strings; the logic stores null for "All". Variant keys are-// restricted to [a-zA-Z0-9_-], so the '$' prefix guarantees no collision with a real variant — a-// variant literally named "all" just renders as its own option after the built-in "All".+// LemonSegmentedButton values must be strings; the logic stores null for "All". '$' is not an+// allowed character in variant keys, so the '$' prefix guarantees no collision with a real+// variant — a variant literally named "all" just renders as its own option after the built-in "All".const ALL_VARIANTS = '$all'export function ExperimentReplayTab({ experiment }: { experiment: Experiment }): JSX.Element {diff --git a/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx b/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsxindex 1789077cf2dd..91eace814cf9 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx@@ -46,7 +46,7 @@ import {describeCron,featureFlagLogic,PAIRED_PRESETS,- validateFeatureFlagKey,+ validateFeatureFlagVariantKey,variantKeyToIndexFeatureFlagPayloads,} from './featureFlagLogic'import { FeatureFlagReleaseConditionsCollapsible } from './FeatureFlagReleaseConditionsCollapsible'@@ -467,7 +467,7 @@ export default function FeatureFlagSchedule(): JSX.Element {)const variantErrors = displayVariants.map(({ key: variantKey }) => ({- key: validateFeatureFlagKey(variantKey),+ key: validateFeatureFlagVariantKey(variantKey),}))const supportsRecurring = RECURRING_SUPPORTED_OPERATIONS.has(scheduledChangeOperation)diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.test.tsindex 5281d4901d0a..56ecae2f8bf7 100644--- a/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.test.ts@@ -55,6 +55,7 @@ import {scheduleDateToProjectTzISO,slugifyFeatureFlagKey,validateFeatureFlagKey,+ validateFeatureFlagVariantKey,} from './featureFlagLogic'import { featureFlagsLogic } from './featureFlagsLogic'@@ -2271,6 +2272,27 @@ describe('validateFeatureFlagKey', () => {})})+describe('validateFeatureFlagVariantKey', () => {+ it.each([+ { key: 'control', desc: 'plain key' },+ { key: 'provider/model-1.2', desc: 'slashes and dots (model-id style)' },+ { key: '0.85', desc: 'dotted number' },+ { key: 'a/b/c.d_e-f', desc: 'mixed dots, slashes, hyphens, underscores' },+ ])('accepts valid variant key: $desc', ({ key }) => {+ expect(validateFeatureFlagVariantKey(key)).toBeUndefined()+ })++ it.each([+ { key: 'foo bar', error: 'Only letters', desc: 'spaces' },+ { key: 'foo,bar', error: 'Only letters', desc: 'commas' },+ { key: 'foo?bar', error: 'Only letters', desc: 'question marks' },+ { key: '', error: 'Please set a key', desc: 'empty key' },+ { key: 'a'.repeat(401), error: '400 characters', desc: 'over 400 characters' },+ ])('rejects variant key with $desc', ({ key, error }) => {+ expect(validateFeatureFlagVariantKey(key)).toContain(error)+ })+})+describe('variant reordering', () => {let logic: ReturnType<typeof featureFlagLogic.build>diff --git a/frontend/src/scenes/feature-flags/featureFlagLogic.ts b/frontend/src/scenes/feature-flags/featureFlagLogic.tsindex 4d15f39f2c09..e96b2f8ab2ad 100644--- a/frontend/src/scenes/feature-flags/featureFlagLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagLogic.ts@@ -442,6 +442,19 @@ export function validateFeatureFlagKey(key: string): string | undefined {: undefined}+/** Check whether a string is a valid variant key. If not, a reason string is returned - otherwise undefined.+ * Wider than flag keys: dots and slashes are allowed because variant keys often carry values SDKs consume+ * directly (e.g. model IDs like "provider/model-1.2"), and the API has always accepted them. */+export function validateFeatureFlagVariantKey(key: string): string | undefined {+ return !key+ ? 'Please set a key'+ : key.length > 400+ ? 'Key must be 400 characters or less.'+ : !key.match?.(/^[a-zA-Z0-9_\-./]+$/)+ ? 'Only letters, numbers, hyphens (-), underscores (_), dots (.) & slashes (/) are allowed.'+ : undefined+}+function validatePayloadRequired(is_remote_configuration: boolean, payload?: JsonType): string | undefined {if (!is_remote_configuration) {return undefined@@ -2033,7 +2046,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([multivariate: {variants: filters?.multivariate?.variants?.map(({ key: variantKey }: MultivariateFlagVariant) => ({- key: validateFeatureFlagKey(variantKey),+ key: validateFeatureFlagVariantKey(variantKey),})),},@@ -4152,7 +4165,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([(s) => [s.variants],(variants: MultivariateFlagVariant[]) => {const errors: VariantError[] = variants.map(({ key: variantKey }: MultivariateFlagVariant) => ({- key: validateFeatureFlagKey(variantKey),+ key: validateFeatureFlagVariantKey(variantKey),}))return errors},