: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): disable group targeting on early access flags in the editor (#81974)
ruby childsfdddf6ec9f68
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagForm.tsx b/frontend/src/scenes/feature-flags/FeatureFlagForm.tsxindex aa3bef9d6632..574f34cddd9c 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagForm.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagForm.tsx@@ -160,6 +160,7 @@ export function FeatureFlagForm({ id }: FeatureFlagLogicProps): JSX.Element {payloadExpanded,expandAdvancedOnEdit,hasEncryptedPayloadBeenSaved,+ hasEarlyAccessFeatures,} = useValues(featureFlagLogic)const {setMultivariateEnabled,@@ -1066,6 +1067,7 @@ export function FeatureFlagForm({ id }: FeatureFlagLogicProps): JSX.Element {variants={nonEmptyVariants}isDisabled={!featureFlag.active}bucketingIdentifier={featureFlag.bucketing_identifier}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}onBucketingIdentifierChange={(value: FeatureFlagBucketingIdentifier | null) => {// Always go through setFeatureFlag so this caller and// FeatureFlagReleaseConditions use the same shape — listeners ondiff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.earlyAccessGroupTargeting.test.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.earlyAccessGroupTargeting.test.tsxnew file mode 100644index 000000000000..35bef566752d--- /dev/null+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.earlyAccessGroupTargeting.test.tsx@@ -0,0 +1,123 @@+import '@testing-library/jest-dom'++import { cleanup, render, waitFor } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { mockGetEventDefinitions, mockGetPropertyDefinitions } from '~/test/mocks'+import { FeatureFlagGroupType, FeatureFlagType } from '~/types'++import { EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON } from './constants'+import { FeatureFlagReleaseConditionsCollapsible } from './FeatureFlagReleaseConditionsCollapsible'++jest.mock('lib/components/AutoSizer', () => ({+ AutoSizer: ({ renderProp }: { renderProp: (size: { height: number; width: number }) => React.ReactNode }) =>+ renderProp({ height: 400, width: 400 }),+}))++function buildFilters(): FeatureFlagType['filters'] {+ const group: FeatureFlagGroupType = {+ properties: [],+ rollout_percentage: 100,+ variant: null,+ sort_key: 'group-1',+ }+ return { groups: [group], multivariate: null, payloads: {} }+}++async function openTargetByAndGetGroupOption(): Promise<HTMLButtonElement> {+ await waitFor(() => {+ expect(document.querySelector('[data-attr="condition-set-0-aggregation"]')).toBeInTheDocument()+ })+ await userEvent.click(document.querySelector('[data-attr="condition-set-0-aggregation"]')!)++ // 'organizations' is seeded by initKeaTests() from MOCK_DEFAULT_TEAM.group_types;+ // the groups_types API mock returns an empty list, so it is not the source here+ let option: HTMLButtonElement | undefined+ await waitFor(() => {+ option = Array.from(document.querySelectorAll('button')).find(+ (button) => button.textContent === 'organizations'+ )+ expect(option).not.toBeUndefined()+ })+ return option!+}++describe('release condition group targeting on early access flags', () => {+ beforeEach(() => {+ initKeaTests()+ useMocks({+ get: {+ '/api/projects/:team/event_definitions': mockGetEventDefinitions,+ '/api/projects/:team/property_definitions': mockGetPropertyDefinitions,+ '/api/projects/:team/cohorts/': { results: [], next: null, count: 0 },+ '/api/projects/:team/actions': { results: [] },+ '/api/projects/:team/feature_flags/1234/': {+ id: 1234,+ key: 'test-flag',+ filters: { groups: [], multivariate: null, payloads: {} },+ },+ },+ post: {+ '/api/environments/:team/query': { results: [] },+ '/api/projects/:team/feature_flags/user_blast_radius': () => [200, { affected: 0, total: 2 }],+ },+ })+ })++ afterEach(() => {+ cleanup()+ })++ it('disables the group type when the flag is linked to an early access feature', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditionsCollapsible+ id="1234"+ flagId={1234}+ filters={buildFilters()}+ onChange={jest.fn()}+ hasEarlyAccessFeatures+ />+ </Provider>+ )++ const organizations = await openTargetByAndGetGroupOption()++ expect(organizations).toHaveAttribute('aria-disabled', 'true')++ // The gate must disable only group types, not the whole "Target by" list+ const users = Array.from(document.querySelectorAll('[role="menuitem"]')).find(+ (el) => el.textContent === 'Users'+ )+ expect(users).toHaveAttribute('aria-disabled', 'false')++ await userEvent.hover(organizations)+ await waitFor(() => {+ expect(document.body).toHaveTextContent(EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON)+ })++ // Clicking the disabled option must not change the aggregation+ await userEvent.click(organizations)+ expect(document.querySelector('[data-attr="condition-set-0-aggregation"]')).toHaveTextContent('Users')+ })++ it('leaves the group type selectable when no early access feature is linked', async () => {+ render(+ <Provider>+ <FeatureFlagReleaseConditionsCollapsible+ id="1234"+ flagId={1234}+ filters={buildFilters()}+ onChange={jest.fn()}+ />+ </Provider>+ )++ const organizations = await openTargetByAndGetGroupOption()++ expect(organizations).toHaveAttribute('aria-disabled', 'false')+ })+})diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsxindex e71d0b532289..b7478d7eeab5 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditions.tsx@@ -44,7 +44,7 @@ import {} from '~/types'import { resolveAggregationGroupTypeIndex } from './aggregation'-import { MATCHING_ESTIMATE_TOOLTIP } from './constants'+import { EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON, MATCHING_ESTIMATE_TOOLTIP } from './constants'import { featureFlagLogic } from './featureFlagLogic'import {FeatureFlagReleaseConditionsLogicProps,@@ -699,7 +699,7 @@ export function FeatureFlagReleaseConditions({description:'Stable assignment for everyone in an organization, company, or other custom group type.',disabledReason: hasEarlyAccessFeatures- ? 'This feature flag cannot be group-based, because it is linked to an early access feature.'+ ? EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON: groupTypes.size === 0? 'No group types defined. Set up group analytics first.': undefined,diff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsxindex f7cb1d00f5eb..53b4b84832b3 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx@@ -73,7 +73,7 @@ import {import { INTENT_METADATA } from 'products/feature_flags/frontend/featureFlagTemplateConstants'import { resolveAggregationGroupTypeIndex } from './aggregation'-import { MATCHING_ESTIMATE_TOOLTIP } from './constants'+import { EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON, MATCHING_ESTIMATE_TOOLTIP } from './constants'import { EarlyExitIndicator } from './EarlyExitIndicator'import { FeatureFlagConditionDragHandle } from './FeatureFlagConditionDragHandle'import { FeatureFlagConditionWarning } from './FeatureFlagConditionWarning'@@ -99,6 +99,12 @@ interface FeatureFlagReleaseConditionsCollapsibleProps extends FeatureFlagReleasevaluationRuntime?: FeatureFlagEvaluationRuntime/** When true, hides the "Match by" User/Group selector. Use when the aggregation type is inherited from the parent flag. */hideMatchOptions?: boolean+ /**+ * When true, group targeting is disabled per condition set. Early access feature enrollment is+ * held in the `$feature_enrollment/<key>` person property, which a group-aggregated condition+ * cannot read, so the API rejects the save.+ */+ hasEarlyAccessFeatures?: boolean/** When true, hides the early exit toggle. Use in contexts where early_exit cannot be persisted (e.g. default release conditions). */hideEarlyExit?: boolean}@@ -349,6 +355,7 @@ interface ConditionProps {taxonomicGroupTypesForCondition: (conditionGroupTypeIndex: number | null | undefined) => TaxonomicFilterGroupType[]groupTypes: Map<GroupTypeIndex, GroupType>setConditionAggregation: (index: number, groupTypeIndex: number | null) => void+ hasEarlyAccessFeatures?: booleanisDeviceTargeting: booleanonMoveUp: () => voidonMoveDown: () => void@@ -422,6 +429,7 @@ const ConditionContent = ({taxonomicGroupTypesForCondition,groupTypes,setConditionAggregation,+ hasEarlyAccessFeatures,isDeviceTargeting,onMoveUp,onMoveDown,@@ -612,6 +620,9 @@ const ConditionContent = ({gt.group_type.slice(1) +'s',icon: <IconPeople />,+ disabledReason: hasEarlyAccessFeatures+ ? EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON+ : undefined,})),},]}@@ -860,6 +871,7 @@ export function FeatureFlagReleaseConditionsCollapsible({evaluationRuntime,hideMatchOptions,hideEarlyExit,+ hasEarlyAccessFeatures,}: FeatureFlagReleaseConditionsCollapsibleProps): JSX.Element {const releaseConditionsLogic = featureFlagReleaseConditionsLogic({id,@@ -1282,6 +1294,7 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}@@ -1362,6 +1375,7 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}@@ -1416,6 +1430,7 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}@@ -1452,6 +1467,7 @@ export function FeatureFlagReleaseConditionsCollapsible({taxonomicGroupTypesForCondition={taxonomicGroupTypesForCondition}groupTypes={groupTypes}setConditionAggregation={setConditionAggregation}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}isDeviceTargeting={isDeviceTargeting}onMoveUp={() => moveConditionSetUp(index)}onMoveDown={() => moveConditionSetDown(index)}diff --git a/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx b/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsxindex e91f8c7c0987..c96339f33d46 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagSchedule.tsx@@ -414,6 +414,7 @@ export default function FeatureFlagSchedule(): JSX.Element {customPairEnableCronPreview,customPairDisableCronPreview,canCreatePairedSchedule,+ hasEarlyAccessFeatures,} = useValues(featureFlagLogic)const {deleteScheduledChange,@@ -800,6 +801,7 @@ export default function FeatureFlagSchedule(): JSX.Element {filters={scheduleFilters}onChange={(value, errors) => setSchedulePayload(value, null, errors, null, null)}hideMatchOptions+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}/></div></div>diff --git a/frontend/src/scenes/feature-flags/constants.tsx b/frontend/src/scenes/feature-flags/constants.tsxindex 9bbab2edceac..eb002b3efdec 100644--- a/frontend/src/scenes/feature-flags/constants.tsx+++ b/frontend/src/scenes/feature-flags/constants.tsx@@ -3,6 +3,9 @@ import { Link } from '@posthog/lemon-ui'export const COHORT_BEHAVIORAL_LIMITATIONS_URL ='https://posthog.com/docs/feature-flags/common-questions#why-cant-i-use-a-cohort-with-behavioral-filters-in-my-feature-flag'+export const EARLY_ACCESS_GROUP_TARGETING_DISABLED_REASON =+ 'This flag is linked to an early access feature, so it can only target users. Remove the early access feature to target groups.'+export const MATCHING_ESTIMATE_TOOLTIP = (<><div>diff --git a/frontend/src/scenes/feature-flags/featureFlagNotebookWidgetViews.tsx b/frontend/src/scenes/feature-flags/featureFlagNotebookWidgetViews.tsxindex be118b94986d..fb45e3725c59 100644--- a/frontend/src/scenes/feature-flags/featureFlagNotebookWidgetViews.tsx+++ b/frontend/src/scenes/feature-flags/featureFlagNotebookWidgetViews.tsx@@ -192,8 +192,14 @@ function FeatureFlagImplementationWidget({function FeatureFlagCompactEditor({ attributes }: NotebookNodeProps<FeatureFlagNotebookWidgetAttributes>): JSX.Element {const { id } = attributesconst logic = featureFlagLogic({ id })- const { featureFlag, featureFlagLoading, featureFlagMissing, hasUnsavedChanges, nonEmptyVariants } =- useValues(logic)+ const {+ featureFlag,+ featureFlagLoading,+ featureFlagMissing,+ hasUnsavedChanges,+ nonEmptyVariants,+ hasEarlyAccessFeatures,+ } = useValues(logic)const { loadFeatureFlag, setFeatureFlagFilters, submitFeatureFlagWithValidation } = useActions(logic)if (featureFlagMissing) {@@ -228,6 +234,7 @@ function FeatureFlagCompactEditor({ attributes }: NotebookNodeProps<FeatureFlagNisDisabled={!featureFlag.active}bucketingIdentifier={featureFlag.bucketing_identifier}evaluationRuntime={featureFlag.evaluation_runtime}+ hasEarlyAccessFeatures={hasEarlyAccessFeatures}/>)}