: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): show flag key instead of ID in flag dependencies (#66218)
Phill80f99bc919d7
diff --git a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.test.ts b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.test.tsindex a11974620b98..648017551237 100644--- a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.test.ts+++ b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.test.ts@@ -305,5 +305,22 @@ describe('propertyFilterLogic', () => {type: PropertyFilterType.Event,})})++ it('uses the resolved flag label, not the raw flag ID, as the recent item name', async () => {+ const logic = mountLogic({ propertyFilters: [{}] as AnyPropertyFilter[] })+ logic.actions.setFilter(0, {+ key: '2',+ label: 'test-flag',+ type: PropertyFilterType.Flag,+ operator: PropertyOperator.FlagEvaluatesTo,+ value: true,+ })+ await expectLogic(logic).toFinishAllListeners()++ const recents = recentsLogic.values.recentFilters+ expect(recents).toHaveLength(1)+ expect(recents[0].value).toBe('2')+ expect(recents[0].item).toMatchObject({ name: 'test-flag' })+ })})})diff --git a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.tsindex fb40500e708c..1b1e2fd6f7b7 100644--- a/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts+++ b/frontend/src/lib/components/PropertyFilters/propertyFilterLogic.ts@@ -192,11 +192,14 @@ export const propertyFilterLogic = kea<propertyFilterLogicType>([const groupType = PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE[property.type]if (groupType && recentTaxonomicFiltersLogic.isMounted()) {const groupName = TAXONOMIC_GROUP_TYPE_TO_DISPLAY_NAME[groupType] ?? groupType+ // For Flag filters `key` is the numeric flag ID (see FlagPropertyFilter); the+ // human-readable key lives in `label`, set at selection time.+ const displayName = ('label' in property && property.label) || property.keyrecentTaxonomicFiltersLogic.actions.recordRecentFilter({groupType,groupName,value: property.key,- item: { name: property.key },+ item: { name: displayName },teamId: teamLogic.values.currentTeamId ?? undefined,propertyFilter: property,})diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.flagDependencyLabel.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.flagDependencyLabel.test.tsxnew file mode 100644index 000000000000..a17bbc8fafca--- /dev/null+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.flagDependencyLabel.test.tsx@@ -0,0 +1,75 @@+import '@testing-library/jest-dom'++import { cleanup, render, waitFor } from '@testing-library/react'+import { Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import {+ FeatureFlagGroupType,+ FeatureFlagType,+ FlagPropertyFilter,+ PropertyFilterType,+ PropertyOperator,+} from '~/types'++import { FeatureFlagReleaseConditionsCollapsible } from './FeatureFlagReleaseConditionsCollapsible'+import { FeatureFlagReleaseConditionsReadonly } from './FeatureFlagReleaseConditionsReadonly'++const flagDependencyFilter: FlagPropertyFilter = {+ type: PropertyFilterType.Flag,+ key: '42',+ operator: PropertyOperator.FlagEvaluatesTo,+ value: true,+}++function buildFilters(): FeatureFlagType['filters'] {+ const group: FeatureFlagGroupType = {+ properties: [flagDependencyFilter],+ rollout_percentage: 100,+ variant: null,+ sort_key: 'group-1',+ }+ return { groups: [group], multivariate: null, payloads: {} }+}++describe('feature flag release conditions flag dependency label', () => {+ beforeEach(() => {+ initKeaTests()+ useMocks({+ post: {+ '/api/projects/:team/feature_flags/bulk_keys/': [200, { keys: { '42': 'beta-banner' } }],+ },+ })+ })++ afterEach(() => {+ cleanup()+ })++ it('shows the resolved flag key, not the raw ID, in the readonly condition card', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditionsReadonly id="1234" filters={buildFilters()} />+ </Provider>+ )++ await waitFor(() => {+ expect(document.body).toHaveTextContent('beta-banner')+ })+ expect(document.body.textContent).not.toMatch(/\b42\b/)+ })++ it('shows the resolved flag key, not the raw ID, in the collapsed condition summary', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditionsCollapsible id="1234" filters={buildFilters()} readOnly />+ </Provider>+ )++ await waitFor(() => {+ expect(document.body).toHaveTextContent('beta-banner')+ })+ expect(document.body.textContent).not.toMatch(/\b42\b/)+ })+})diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsxindex ce050d411085..061701009688 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx@@ -50,6 +50,7 @@ import {FeatureFlagReleaseConditionsLogicProps,featureFlagReleaseConditionsLogic,isDistinctIdFilter,+ withResolvedFlagLabels,} from './featureFlagReleaseConditionsLogic'import { getPropertySelectErrorMessages } from './propertySelectErrorMessages'@@ -367,7 +368,7 @@ export function FeatureFlagReleaseConditions({pageKey={`feature-flag-${id}-${group.sort_key}-${filterGroups.length}-${filters.aggregation_group_type_index ?? ''}`}- propertyFilters={group?.properties}+ propertyFilters={withResolvedFlagLabels(group?.properties, getFlagKey)}logicalRowDivideraddText="Add condition"onChange={(properties) => updateConditionSet(index, undefined, properties)}diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsxindex 06c7c05f10b6..12139173a5c5 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx@@ -84,6 +84,7 @@ import {FeatureFlagGroupTypeWithSortKey,featureFlagReleaseConditionsLogic,isDistinctIdFilter,+ withResolvedFlagLabels,} from './featureFlagReleaseConditionsLogic'import { getPropertySelectErrorMessages, PropertySelectError } from './propertySelectErrorMessages'@@ -116,7 +117,8 @@ type MatchByOption = {function summarizeProperties(properties: AnyPropertyFilter[],aggregationTargetName: string,- getDistinctIdName: (distinctId: string) => string+ getDistinctIdName: (distinctId: string) => string,+ getFlagKey: (flagId: string) => string): string {if (!properties || properties.length === 0) {// Capitalize first letter of aggregation target name@@ -129,7 +131,8 @@ function summarizeProperties(if (property.type === PropertyFilterType.Cohort) {key = 'Cohort'} else if (property.type === PropertyFilterType.Flag) {- key = property.label || property.key || 'flag'+ const resolved = withResolvedFlagLabels([property], getFlagKey)[0]+ key = (resolved.type === PropertyFilterType.Flag && resolved.label) || 'flag'} else {key = property.key || 'property'}@@ -178,6 +181,7 @@ interface ConditionHeaderProps {affectedCount: number | undefinedaggregationTargetName: stringgetDistinctIdName: (distinctId: string) => string+ getFlagKey: (flagId: string) => stringonDuplicate: () => voidonRemove: () => void}@@ -189,12 +193,14 @@ function ConditionHeader({affectedCount,aggregationTargetName,getDistinctIdName,+ getFlagKey,onDuplicate,onRemove,}: ConditionHeaderProps): JSX.Element {// Use description if available, otherwise summarize the filtersconst summary =- group.description || summarizeProperties(group.properties || [], aggregationTargetName, getDistinctIdName)+ group.description ||+ summarizeProperties(group.properties || [], aggregationTargetName, getDistinctIdName, getFlagKey)const rollout = group.rollout_percentage ?? 100const actualCount =@@ -338,6 +344,7 @@ interface ConditionProps {) => voidaggregationTargetName: (conditionGroupTypeIndex?: number | null) => stringgetDistinctIdName: (distinctId: string) => string+ getFlagKey: (flagId: string) => stringtaxonomicGroupTypesForCondition: (conditionGroupTypeIndex: number | null | undefined) => TaxonomicFilterGroupType[]groupTypes: Map<GroupTypeIndex, GroupType>setConditionAggregation: (index: number, groupTypeIndex: number | null) => void@@ -410,6 +417,7 @@ const ConditionContent = ({calculateBlastRadiusForCondition,aggregationTargetName,getDistinctIdName,+ getFlagKey,taxonomicGroupTypesForCondition,groupTypes,setConditionAggregation,@@ -540,6 +548,7 @@ const ConditionContent = ({affectedCount={group.sort_key ? affectedCounts[group.sort_key] : undefined}aggregationTargetName={aggregationTargetName(group.aggregation_group_type_index)}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}onDuplicate={onDuplicate}onRemove={onRemove}/>@@ -615,7 +624,7 @@ const ConditionContent = ({<PropertyFiltersorFiltering={true}pageKey={`feature-flag-workflow-${id}-${group.sort_key!}`}- propertyFilters={group?.properties}+ propertyFilters={withResolvedFlagLabels(group?.properties, getFlagKey)}logicalRowDivideraddText="Add filter"onChange={(properties) => {@@ -869,6 +878,7 @@ export function FeatureFlagReleaseConditionsCollapsible({blastRadiusErrors,aggregationTargetName,getDistinctIdName,+ getFlagKey,taxonomicGroupTypesForCondition,filters: releaseFilters,groupTypes,@@ -969,7 +979,8 @@ export function FeatureFlagReleaseConditionsCollapsible({summarizeProperties(group.properties || [],aggregationTargetName(group.aggregation_group_type_index),- getDistinctIdName+ getDistinctIdName,+ getFlagKey)const rollout = group.rollout_percentage ?? 100return (@@ -1269,6 +1280,7 @@ export function FeatureFlagReleaseConditionsCollapsible({calculateBlastRadiusForCondition={calculateBlastRadiusForCondition}aggregationTargetName={aggregationTargetName}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}@@ -1312,7 +1324,8 @@ export function FeatureFlagReleaseConditionsCollapsible({aggregationTargetName(draggedGroup.aggregation_group_type_index),- getDistinctIdName+ getDistinctIdName,+ getFlagKey)}</span></div>@@ -1347,6 +1360,7 @@ export function FeatureFlagReleaseConditionsCollapsible({calculateBlastRadiusForCondition={calculateBlastRadiusForCondition}aggregationTargetName={aggregationTargetName}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}@@ -1400,6 +1414,7 @@ export function FeatureFlagReleaseConditionsCollapsible({calculateBlastRadiusForCondition={calculateBlastRadiusForCondition}aggregationTargetName={aggregationTargetName}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}@@ -1435,6 +1450,7 @@ export function FeatureFlagReleaseConditionsCollapsible({calculateBlastRadiusForCondition={calculateBlastRadiusForCondition}aggregationTargetName={aggregationTargetName}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsReadonly.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsReadonly.tsxindex 8d5fc35cd85f..a06c248f8eb8 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsReadonly.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsReadonly.tsx@@ -20,7 +20,11 @@ import {import { EarlyExitIndicator } from './EarlyExitIndicator'import { FeatureFlagConditionWarning } from './FeatureFlagConditionWarning'-import { featureFlagReleaseConditionsLogic, isDistinctIdFilter } from './featureFlagReleaseConditionsLogic'+import {+ featureFlagReleaseConditionsLogic,+ isDistinctIdFilter,+ withResolvedFlagLabels,+} from './featureFlagReleaseConditionsLogic'interface FeatureFlagReleaseConditionsReadonlyProps {id: string@@ -124,7 +128,8 @@ export function FeatureFlagReleaseConditionsReadonly({filters,})- const { filterGroups, aggregationTargetName, properties, getDistinctIdName } = useValues(releaseConditionsLogic)+ const { filterGroups, aggregationTargetName, properties, getDistinctIdName, getFlagKey } =+ useValues(releaseConditionsLogic)return (<div className="flex flex-col gap-2">@@ -158,6 +163,7 @@ export function FeatureFlagReleaseConditionsReadonly({index={index}aggregationTargetName={aggregationTargetName(group.aggregation_group_type_index)}getDistinctIdName={getDistinctIdName}+ getFlagKey={getFlagKey}/></div>))}@@ -175,6 +181,7 @@ interface ConditionSetCardProps {index: numberaggregationTargetName: stringgetDistinctIdName: (distinctId: string) => string+ getFlagKey: (flagId: string) => string}function ConditionSetCard({@@ -182,8 +189,9 @@ function ConditionSetCard({index,aggregationTargetName,getDistinctIdName,+ getFlagKey,}: ConditionSetCardProps): JSX.Element {- const properties = group.properties || []+ const properties = withResolvedFlagLabels(group.properties, getFlagKey)const rollout = group.rollout_percentage ?? 100const getSummary = (): JSX.Element => {diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.tsindex 5679d8fea4b2..4cc7c056c9e1 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.test.ts@@ -10,13 +10,14 @@ import {AnyPropertyFilter,FeatureFlagGroupType,FeatureFlagType,+ FlagPropertyFilter,MultivariateFlagOptions,PropertyFilterType,PropertyOperator,} from '~/types'import { resolveAggregationGroupTypeIndex } from './aggregation'-import { featureFlagReleaseConditionsLogic } from './featureFlagReleaseConditionsLogic'+import { featureFlagReleaseConditionsLogic, withResolvedFlagLabels } from './featureFlagReleaseConditionsLogic'jest.mock('uuid', () => ({v4: jest.fn(),@@ -1705,6 +1706,78 @@ describe('the feature flag release conditions logic', () => {})})+ describe('withResolvedFlagLabels', () => {+ // Flag dependencies store the numeric flag ID in `key`; `getFlagKey` resolves it to the slug+ // and falls back to the raw ID when the cache hasn't resolved it yet.+ const flagKeys: Record<string, string> = { '10': 'beta-banner', '20': 'new-checkout' }+ const getFlagKey = (flagId: string): string => flagKeys[flagId] ?? flagId++ const flagFilter = (key: string, label?: string): FlagPropertyFilter =>+ ({+ type: PropertyFilterType.Flag,+ operator: PropertyOperator.FlagEvaluatesTo,+ key,+ value: true,+ ...(label !== undefined ? { label } : {}),+ }) as FlagPropertyFilter++ it('backfills the resolved flag key onto label while keeping the ID in key', () => {+ const [result] = withResolvedFlagLabels([flagFilter('10')], getFlagKey) as FlagPropertyFilter[]+ expect(result.label).toBe('beta-banner')+ // `key` still holds the ID the backend evaluates against — only the display label changes+ expect(result.key).toBe('10')+ })++ it('leaves non-flag filters untouched by reference', () => {+ const personFilter = {+ type: PropertyFilterType.Person,+ key: 'email',+ operator: PropertyOperator.Exact,+ value: '[email protected]',+ } as AnyPropertyFilter+ expect(withResolvedFlagLabels([personFilter], getFlagKey)[0]).toBe(personFilter)+ })++ it('does not inject the raw ID as a label while the key is unresolved', () => {+ // 999 is not in the cache, so getFlagKey returns the ID — we must not show it as a name+ const unresolved = flagFilter('999')+ const [result] = withResolvedFlagLabels([unresolved], getFlagKey) as FlagPropertyFilter[]+ expect(result.label).toBeUndefined()+ expect(result).toBe(unresolved)+ })++ it('re-resolves over a stale label instead of trusting it', () => {+ // A label injected earlier round-trips back through onChange; if the flag was renamed the+ // cache now holds a different key and the stale label must be overridden, not kept.+ const stale = flagFilter('20', 'old-checkout-name')+ const [result] = withResolvedFlagLabels([stale], getFlagKey) as FlagPropertyFilter[]+ expect(result.label).toBe('new-checkout')+ })++ it('returns the same object when the label already matches the resolved key', () => {+ // Avoids creating a new object every render, which would churn re-renders and onChange+ const fresh = flagFilter('10', 'beta-banner')+ expect(withResolvedFlagLabels([fresh], getFlagKey)[0]).toBe(fresh)+ })++ it('handles undefined properties', () => {+ expect(withResolvedFlagLabels(undefined, getFlagKey)).toEqual([])+ })++ it('resolves only flag filters in a mixed array, preserving order', () => {+ const personFilter = {+ type: PropertyFilterType.Person,+ key: 'email',+ operator: PropertyOperator.Exact,+ value: '[email protected]',+ } as AnyPropertyFilter+ const result = withResolvedFlagLabels([personFilter, flagFilter('10'), flagFilter('20')], getFlagKey)+ expect(result[0]).toBe(personFilter)+ expect((result[1] as FlagPropertyFilter).label).toBe('beta-banner')+ expect((result[2] as FlagPropertyFilter).label).toBe('new-checkout')+ })+ })+describe('propsChanged does not clobber fresher local edits', () => {it('keeps a local rollout edit when the parent prop has not caught up', async () => {logic?.unmount()diff --git a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.tsindex 5b2b920bdc52..e98e7982a5ef 100644--- a/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts+++ b/frontend/src/scenes/feature-flags/featureFlagReleaseConditionsLogic.ts@@ -62,6 +62,28 @@ function getPropertyValueError(property: AnyPropertyFilter): string | undefinedreturn undefined}+// Flag-dependency filters store the numeric flag ID in `key`. Backfill the human-readable flag+// key onto `label` (which every display surface prefers) so the UI never shows a bare ID once+// `getFlagKey` has resolved it. We re-resolve from the cache on every call rather than trusting an+// existing `label`: the editable PropertyFilters round-trips the injected label back through+// `onChange` into state, so a stale label could otherwise stick (e.g. after a flag rename). When+// the key isn't resolved yet (`getFlagKey` returns the raw ID) we leave the filter untouched.+export function withResolvedFlagLabels(+ properties: AnyPropertyFilter[] | undefined,+ getFlagKey: (flagId: string) => string+): AnyPropertyFilter[] {+ return (properties ?? []).map((property) => {+ if (property.type !== PropertyFilterType.Flag || !property.key) {+ return property+ }+ const resolved = getFlagKey(property.key)+ if (!resolved || resolved === property.key || resolved === property.label) {+ return property+ }+ return { ...property, label: resolved }+ })+}+// Server caps batch_by_distinct_ids per request; chunk client-side so every id resolves.const DISTINCT_ID_BATCH_SIZE = 200