Skip to content

: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.

feat(early-access-features): require description on PostHog's own project (#72379)

Joe Martin022b18d37dd6
diff --git a/products/early_access_features/backend/api.py b/products/early_access_features/backend/api.py
index 9fc96e93d882..5a3c499383fc 100644
--- a/products/early_access_features/backend/api.py
+++ b/products/early_access_features/backend/api.py
@@ -1,5 +1,6 @@
from typing import Any
+from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import JsonResponse
from django.utils.text import slugify
@@ -22,7 +23,7 @@ from posthog.models.team.team import Team
from posthog.models.utils import uuid7
from posthog.rbac.access_control_api_mixin import AccessControlViewSetMixin
from posthog.rbac.user_access_control import UserAccessControl, UserAccessControlSerializerMixin
-from posthog.tasks.early_access_feature import send_events_for_early_access_feature_stage_change
+from posthog.tasks.early_access_feature import POSTHOG_TEAM_ID, send_events_for_early_access_feature_stage_change
from posthog.utils_cors import cors_response
from products.feature_flags.backend.api.feature_flag import (
@@ -398,6 +399,13 @@ class EarlyAccessFeatureSerializerCreateOnly(EarlyAccessFeatureSerializer):
read_only_fields = ["id", "feature_flag", "created_at", "created_by"]
def validate(self, data):
+ # PostHog's own dogfooding project requires a description on every new early access feature.
+ # Scoped to US cloud specifically: project ids are allocated per region, so id 2 is only
+ # PostHog's own team on US — on EU/DEV/E2E it belongs to an unrelated customer.
+ is_us_cloud = (settings.CLOUD_DEPLOYMENT or "").upper() == "US"
+ if is_us_cloud and self.context["team_id"] == POSTHOG_TEAM_ID and not (data.get("description") or "").strip():
+ raise serializers.ValidationError({"description": "A description is required for early access features."})
+
feature_flag_id = data.get("feature_flag_id", None)
feature_flag = None
diff --git a/products/early_access_features/backend/test/test_early_access_feature.py b/products/early_access_features/backend/test/test_early_access_feature.py
index bcc5e146b039..2fbdf2b53ce6 100644
--- a/products/early_access_features/backend/test/test_early_access_feature.py
+++ b/products/early_access_features/backend/test/test_early_access_feature.py
@@ -119,6 +119,83 @@ class TestEarlyAccessFeature(APIBaseTest):
assert "super_groups" not in response_data["feature_flag"]["filters"]
assert response_data["feature_flag"]["filters"]["feature_enrollment"] is True
+ @parameterized.expand(
+ [
+ ("omitted", None),
+ ("blank", ""),
+ ("whitespace_only", " "),
+ ]
+ )
+ def test_posthog_team_requires_description_on_us_cloud(self, _name, description):
+ with (
+ self.settings(CLOUD_DEPLOYMENT="US"),
+ patch("products.early_access_features.backend.api.POSTHOG_TEAM_ID", self.team.id),
+ ):
+ data: dict = {"name": "Hick bondoogling", "stage": "concept"}
+ if description is not None:
+ data["description"] = description
+
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/early_access_feature/",
+ data=data,
+ format="json",
+ )
+ response_data = response.json()
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST, response_data
+ assert response_data["attr"] == "description"
+ assert not EarlyAccessFeature.objects.filter(name="Hick bondoogling").exists()
+
+ def test_posthog_team_allows_creation_with_description_on_us_cloud(self):
+ with (
+ self.settings(CLOUD_DEPLOYMENT="US"),
+ patch("products.early_access_features.backend.api.POSTHOG_TEAM_ID", self.team.id),
+ ):
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/early_access_feature/",
+ data={"name": "Hick bondoogling", "description": "A real description", "stage": "concept"},
+ format="json",
+ )
+ response_data = response.json()
+
+ assert response.status_code == status.HTTP_201_CREATED, response_data
+ assert response_data["description"] == "A real description"
+
+ def test_other_team_does_not_require_description_on_us_cloud(self):
+ with (
+ self.settings(CLOUD_DEPLOYMENT="US"),
+ patch("products.early_access_features.backend.api.POSTHOG_TEAM_ID", self.team.id + 1000),
+ ):
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/early_access_feature/",
+ data={"name": "Hick bondoogling", "stage": "concept"},
+ format="json",
+ )
+ response_data = response.json()
+
+ assert response.status_code == status.HTTP_201_CREATED, response_data
+
+ @parameterized.expand(
+ [
+ ("eu_cloud", "EU"),
+ ("self_hosted", ""),
+ ]
+ )
+ def test_team_id_2_does_not_require_description_outside_us_cloud(self, _name, cloud_deployment):
+ # project id 2 is PostHog's own team only on US cloud — elsewhere it's an unrelated customer.
+ with (
+ self.settings(CLOUD_DEPLOYMENT=cloud_deployment),
+ patch("products.early_access_features.backend.api.POSTHOG_TEAM_ID", self.team.id),
+ ):
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/early_access_feature/",
+ data={"name": "Hick bondoogling", "stage": "concept"},
+ format="json",
+ )
+ response_data = response.json()
+
+ assert response.status_code == status.HTTP_201_CREATED, response_data
+
@parameterized.expand(
[
(EarlyAccessFeature.Stage.ALPHA,),
diff --git a/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts b/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts
index 7123be348268..01f15e891a8d 100644
--- a/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts
+++ b/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts
@@ -1,14 +1,17 @@
-import { MOCK_TEAM_ID } from 'lib/api.mock'
+import { MOCK_DEFAULT_TEAM, MOCK_TEAM_ID } from 'lib/api.mock'
import { router } from 'kea-router'
/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */
import { expectLogic } from 'kea-test-utils'
+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
+import { teamLogic } from 'scenes/teamLogic'
+
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { EarlyAccessFeatureStage, EarlyAccessFeatureType, FeatureFlagBasicType } from '~/types'
+import { EarlyAccessFeatureStage, EarlyAccessFeatureType, FeatureFlagBasicType, Region } from '~/types'
-import { earlyAccessFeatureLogic } from './earlyAccessFeatureLogic'
+import { POSTHOG_TEAM_ID, earlyAccessFeatureLogic } from './earlyAccessFeatureLogic'
import { earlyAccessFeaturesLogic } from './earlyAccessFeaturesLogic'
const FEATURE_FLAG: FeatureFlagBasicType = {
@@ -139,4 +142,65 @@ describe('earlyAccessFeatureLogic', () => {
expect(earlyAccessFeaturesLogic.values.earlyAccessFeatures).toEqual([])
expect(router.values.location.pathname).toMatch(/\/early_access_features$/)
})
+
+ // PostHog's own project (US cloud, id 2) requires a description on newly created features.
+ // These guard that the frontend validator matches the backend's create-only + US-cloud scope.
+ describe('description requirement', () => {
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/projects/:team_id/early_access_feature/:id': mockFeature({ id: 'existing-id' }),
+ },
+ })
+ })
+
+ async function mountWith(id: string, teamId: number, region: Region): Promise<void> {
+ logic = earlyAccessFeatureLogic({ id })
+ logic.mount()
+ // Wait for the mounted loaders (including preflightLogic's own fetch of the default
+ // US-region fixture) to settle first, so they can't overwrite the state set below.
+ await expectLogic(logic).toFinishAllListeners()
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, id: teamId })
+ preflightLogic.actions.loadPreflightSuccess({ region } as any)
+ }
+
+ it('requires a description when creating on US-cloud project 2', async () => {
+ await mountWith('new', POSTHOG_TEAM_ID, Region.US)
+ logic.actions.setEarlyAccessFeatureValue('name', 'My feature')
+ logic.actions.setEarlyAccessFeatureValue('description', ' ')
+
+ expect(logic.values.earlyAccessFeatureValidationErrors.description).toEqual('A description is required')
+ })
+
+ it('accepts a valid description when creating on US-cloud project 2', async () => {
+ await mountWith('new', POSTHOG_TEAM_ID, Region.US)
+ logic.actions.setEarlyAccessFeatureValue('name', 'My feature')
+ logic.actions.setEarlyAccessFeatureValue('description', 'A real description')
+
+ expect(logic.values.earlyAccessFeatureValidationErrors.description).toBeUndefined()
+ })
+
+ it('does not require a description for other teams on US cloud', async () => {
+ await mountWith('new', MOCK_TEAM_ID, Region.US)
+ logic.actions.setEarlyAccessFeatureValue('name', 'My feature')
+ logic.actions.setEarlyAccessFeatureValue('description', '')
+
+ expect(logic.values.earlyAccessFeatureValidationErrors.description).toBeUndefined()
+ })
+
+ it('does not require a description for project 2 outside US cloud', async () => {
+ await mountWith('new', POSTHOG_TEAM_ID, Region.EU)
+ logic.actions.setEarlyAccessFeatureValue('name', 'My feature')
+ logic.actions.setEarlyAccessFeatureValue('description', '')
+
+ expect(logic.values.earlyAccessFeatureValidationErrors.description).toBeUndefined()
+ })
+
+ it('does not block editing an existing description-less feature on US-cloud project 2', async () => {
+ await mountWith('existing-id', POSTHOG_TEAM_ID, Region.US)
+ logic.actions.setEarlyAccessFeatureValue('description', '')
+
+ expect(logic.values.earlyAccessFeatureValidationErrors.description).toBeUndefined()
+ })
+ })
})
diff --git a/products/early_access_features/frontend/earlyAccessFeatureLogic.ts b/products/early_access_features/frontend/earlyAccessFeatureLogic.ts
index 624938b87288..4d134ff99914 100644
--- a/products/early_access_features/frontend/earlyAccessFeatureLogic.ts
+++ b/products/early_access_features/frontend/earlyAccessFeatureLogic.ts
@@ -12,6 +12,7 @@ import { tryShowMCPHint } from 'lib/components/MCPHint/mcpHintLogic'
import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { identifierToHuman } from 'lib/utils/strings'
+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -27,14 +28,19 @@ import {
EarlyAccessFeatureTabs,
EarlyAccessFeatureType,
NewEarlyAccessFeatureType,
+ PreflightStatus,
ProjectTreeRef,
PropertyFilterType,
PropertyOperator,
+ Region,
} from '~/types'
import { earlyAccessFeaturesLogic } from './earlyAccessFeaturesLogic'
import { GAPromotionDialogContent } from './GAPromotionDialogContent'
+/** PostHog's own dogfooding project on US cloud — mirrors POSTHOG_TEAM_ID in the backend. */
+export const POSTHOG_TEAM_ID = 2
+
export const NEW_EARLY_ACCESS_FEATURE: NewEarlyAccessFeatureType = {
name: '',
description: '',
@@ -53,6 +59,7 @@ export interface EarlyAccessFeatureLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface earlyAccessFeatureLogicValues {
earlyAccessFeatures: EarlyAccessFeatureType[] // earlyAccessFeaturesLogic
+ preflight: PreflightStatus | null // preflightLogic
currentTeamId: number | null // teamLogic
activeTab: EarlyAccessFeatureTabs
breadcrumbs: Breadcrumb[]
@@ -230,7 +237,14 @@ export const earlyAccessFeatureLogic = kea<earlyAccessFeatureLogicType>([
props({} as EarlyAccessFeatureLogicProps),
key(({ id }) => id),
connect(() => ({
- values: [teamLogic, ['currentTeamId'], earlyAccessFeaturesLogic, ['earlyAccessFeatures']],
+ values: [
+ teamLogic,
+ ['currentTeamId'],
+ earlyAccessFeaturesLogic,
+ ['earlyAccessFeatures'],
+ preflightLogic,
+ ['preflight'],
+ ],
})),
actions({
setEarlyAccessFeatureMissing: true,
@@ -312,9 +326,18 @@ export const earlyAccessFeatureLogic = kea<earlyAccessFeatureLogicType>([
forms(({ actions, props, values }) => ({
earlyAccessFeature: {
defaults: { ...NEW_EARLY_ACCESS_FEATURE } as NewEarlyAccessFeatureType | EarlyAccessFeatureType,
- errors: ({ name, payload }) =>
+ errors: ({ name, description, payload }) =>
({
name: !name ? 'Feature name must be set' : undefined,
+ // Mirrors the backend rule: PostHog's own project (US cloud, id 2) requires a description
+ // on newly created features. Create-only and US-only to match the serializer.
+ description:
+ props.id === 'new' &&
+ values.preflight?.region?.toUpperCase() === Region.US &&
+ values.currentTeamId === POSTHOG_TEAM_ID &&
+ !description?.trim()
+ ? 'A description is required'
+ : undefined,
// payload is edited as a JSON string in the form, but typed as Record<string, any>
payload:
payload && typeof payload === 'string'