: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(api): stop reporting events retention until it is enforced (#100207)
Sam Pennington07ed1e2a7eef
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.tsindex a68437ee83cb..4a6d3b60c3a4 100644--- a/frontend/src/generated/core/api.schemas.ts+++ b/frontend/src/generated/core/api.schemas.ts@@ -2681,10 +2681,6 @@ export interface ProjectBackwardCompatApi {onboarding_tasks?: unknown/** @nullable */web_analytics_pre_aggregated_tables_enabled?: boolean | null- /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog support can change it unless your organization is on the enterprise plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly event_retention_months: number- /** Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: neither you nor PostHog support can turn enforcement off, and the retention window itself only changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly events_retention_enforced: boolean}export type PatchedProjectBackwardCompatApiGroupTypesItem = { [key: string]: unknown }@@ -3542,10 +3538,6 @@ export interface PatchedProjectBackwardCompatApi {onboarding_tasks?: unknown/** @nullable */web_analytics_pre_aggregated_tables_enabled?: boolean | null- /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog support can change it unless your organization is on the enterprise plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly event_retention_months?: number- /** Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: neither you nor PostHog support can turn enforcement off, and the retention window itself only changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly events_retention_enforced?: boolean}/**diff --git a/frontend/src/lib/api.mock.ts b/frontend/src/lib/api.mock.tsindex aaa99faaf0c0..73cfcf31c26d 100644--- a/frontend/src/lib/api.mock.ts+++ b/frontend/src/lib/api.mock.ts@@ -89,8 +89,6 @@ export const MOCK_DEFAULT_TEAM: TeamType = {maskAllInputs: true,},session_recording_retention_period: '30d',- event_retention_months: 84,- events_retention_enforced: false,session_replay_config: null,capture_console_log_opt_in: true,capture_performance_opt_in: true,diff --git a/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts b/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.tsindex 4b2d808bd193..9ed57c3c63dd 100644--- a/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts+++ b/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts@@ -2,11 +2,8 @@ import { MakeLogicType, actions, connect, kea, path, reducers, selectors } fromimport { dayjs } from 'lib/dayjs'import { organizationLogic } from 'scenes/organizationLogic'-import { teamLogic } from 'scenes/teamLogic'-import { TeamType } from '~/types'--import type { OrganizationType, TeamPublicType } from '../../../types'+import type { OrganizationType } from '../../../types'const SNOOZE_DAYS = 30// Don't nag accounts that can't yet have at-risk data: only warn once the account is within 90 days of its@@ -26,7 +23,6 @@ function retentionMonthsLabel(months: number): string {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface dataRetentionBannerLogicValues {currentOrganization: OrganizationType | null // organizationLogic- currentTeam: TeamPublicType | TeamType | null // teamLogicaccountAgeEligible: booleanisSnoozed: booleanretentionApplies: boolean@@ -47,8 +43,7 @@ export interface dataRetentionBannerLogicActions {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface dataRetentionBannerLogicMeta {__keaTypeGenInternalSelectorTypes: {- retentionEnforced: (currentTeam: TeamPublicType | TeamType | null) => boolean- retentionMonths: (currentTeam: TeamPublicType | TeamType | null) => number | null+ retentionEnforced: (retentionMonths: number | null) => booleanretentionPeriodLabel: (retentionMonths: number | null) => string | nullisSnoozed: (snoozedUntil: string | null) => booleanaccountAgeEligible: (currentOrganization: OrganizationType | null, retentionMonths: number | null) => boolean@@ -70,12 +65,14 @@ export type dataRetentionBannerLogicType = MakeLogicType<export const dataRetentionBannerLogic = kea<dataRetentionBannerLogicType>([path(['scenes', 'insights', 'dataRetention', 'dataRetentionBannerLogic']),connect({- values: [teamLogic, ['currentTeam'], organizationLogic, ['currentOrganization']],+ values: [organizationLogic, ['currentOrganization']],}),actions({snooze: true,}),reducers({+ // No source until events retention enforcement ships, see https://github.com/PostHog/posthog/issues/17031+ retentionMonths: [null as number | null, {}],snoozedUntil: [null as string | null,{ persist: true },@@ -86,14 +83,8 @@ export const dataRetentionBannerLogic = kea<dataRetentionBannerLogicType>([}),selectors({retentionEnforced: [- (s) => [s.currentTeam],- (currentTeam: TeamType | null | import('~/types').TeamPublicType): boolean =>- !!(currentTeam as TeamType | null)?.events_retention_enforced,- ],- retentionMonths: [- (s) => [s.currentTeam],- (currentTeam: TeamType | null | import('~/types').TeamPublicType): number | null =>- (currentTeam as TeamType | null)?.event_retention_months ?? null,+ (s) => [s.retentionMonths],+ (retentionMonths: number | null): boolean => retentionMonths !== null,],retentionPeriodLabel: [(s) => [s.retentionMonths],diff --git a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx b/frontend/src/scenes/team-activity/teamActivityDescriber.tsxindex 22183ab33caf..cc23701fd22a 100644--- a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx+++ b/frontend/src/scenes/team-activity/teamActivityDescriber.tsx@@ -755,8 +755,6 @@ const TEAM_PROPERTIES_MAPPING: Record<keyof TeamType, (change: ActivityChange) =managed_viewsets: () => null,workflows_config: () => null,feature_flag_policy_config: () => null,- event_retention_months: () => null,- events_retention_enforced: () => null,}function nameAndLink(logItem?: ActivityLogItem): JSX.Element {diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 009748e077a9..e9f7a567ab41 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -828,14 +828,6 @@ export interface TeamType extends TeamBasicType {| nullsession_recording_masking_config: SessionRecordingMaskingConfig | undefined | nullsession_recording_retention_period: SessionRecordingRetentionPeriod | null- /**- * Plan-derived events data retention window in months (synced from billing). Read-only: it follows the plan's- * data retention entitlement, so support cannot change it outside the enterprise plan.- * See https://github.com/PostHog/posthog/issues/17031- */- event_retention_months: number- /** Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only. */- events_retention_enforced: booleansession_replay_config: { record_canvas?: boolean } | undefined | nullsurvey_config?: TeamSurveyConfigTypelogs_settings?: LogsSettings | nulldiff --git a/posthog/api/project.py b/posthog/api/project.pyindex 0dc1fb4eeed3..42852783febb 100644--- a/posthog/api/project.py+++ b/posthog/api/project.py@@ -85,7 +85,6 @@ from posthog.models.product_intent.product_intent import (enqueue_product_activation_calc_debounced,)from posthog.models.project import Project-from posthog.models.team.event_retention import should_enforce_events_retentionfrom posthog.models.team.extensions import get_or_create_team_extensionfrom posthog.models.team.setup_tasks import SetupTaskIdfrom posthog.models.team.team import CURRENCY_CODE_CHOICES, Team@@ -592,13 +591,6 @@ class ProjectBackwardCompatSerializer(product_intents = serializers.SerializerMethodField() # Compat with TeamSerializeravailable_setup_task_ids = serializers.SerializerMethodField() # Compat with TeamSerializermanaged_viewsets = serializers.SerializerMethodField() # Compat with TeamSerializer- events_retention_enforced = serializers.SerializerMethodField(- help_text=(- "Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: "- "neither you nor PostHog support can turn enforcement off, and the retention window itself only "- "changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031"- )- ) # Compat with TeamSerializer# These are @property attrs on Team, not Django model fields — declare explicitly so drf-spectacular can resolve themdefault_modifiers = serializers.DictField(read_only=True) # Compat with TeamSerializerperson_on_events_querying_enabled = serializers.BooleanField(read_only=True) # Compat with TeamSerializer@@ -736,8 +728,6 @@ class ProjectBackwardCompatSerializer("default_data_theme", # Compat with TeamSerializer"onboarding_tasks", # Compat with TeamSerializer"web_analytics_pre_aggregated_tables_enabled", # Compat with TeamSerializer- "event_retention_months", # Compat with TeamSerializer- "events_retention_enforced", # Compat with TeamSerializer)read_only_fields = ("id",@@ -761,7 +751,6 @@ class ProjectBackwardCompatSerializer("project_id","user_access_level","managed_viewsets",- "event_retention_months",)team_passthrough_fields = {@@ -839,7 +828,6 @@ class ProjectBackwardCompatSerializer("customer_analytics_config","workflows_config","feature_flag_policy_config",- "event_retention_months",}# help_text entries flow into the generated OpenAPI spec, frontend types, and MCP tool schemas.@@ -887,15 +875,6 @@ class ProjectBackwardCompatSerializer("How long to retain new session recordings. One of `30d`, `90d`, `1y`, or `5y` (availability depends on plan).")},- "event_retention_months": {- "help_text": (- "The team's events data retention window in months (plan-derived, synced from billing). When "- "retention enforcement is active for the team, queries do not return events older than this many "- "months. Read-only: this value follows your plan's data retention entitlement, so neither you nor "- "PostHog support can change it unless your organization is on the enterprise plan. Background and "- "discussion: https://github.com/PostHog/posthog/issues/17031"- )- },"data_attributes": {"help_text": ("Element attributes that posthog-js should capture as action identifiers (e.g. `['data-attr']`)."@@ -950,10 +929,6 @@ class ProjectBackwardCompatSerializer()return {kind: (kind in enabled_set) for kind, _ in DataWarehouseManagedViewSetKind.choices}- @extend_schema_field(serializers.BooleanField())- def get_events_retention_enforced(self, obj: Project) -> bool:- return should_enforce_events_retention(obj.passthrough_team.id)-@staticmethoddef validate_revenue_analytics_config(value):return TeamSerializer.validate_revenue_analytics_config(value)diff --git a/posthog/api/team.py b/posthog/api/team.pyindex c3dd56f88795..d226f607fd30 100644--- a/posthog/api/team.py+++ b/posthog/api/team.py@@ -75,7 +75,6 @@ from posthog.models.product_intent.product_intent import (enqueue_product_activation_calc_debounced,)from posthog.models.project import Project-from posthog.models.team.event_retention import should_enforce_events_retentionfrom posthog.models.team.extensions import get_or_create_team_extensionfrom posthog.models.team.setup_tasks import SetupTaskIdfrom posthog.models.team.team import CURRENCY_CODE_CHOICES, DEFAULT_CURRENCY@@ -1211,23 +1210,6 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixinworkflows_config = TeamWorkflowsConfigSerializer(required=False)feature_flag_policy_config = TeamFeatureFlagPolicyConfigSerializer(required=False)base_currency = serializers.ChoiceField(choices=CURRENCY_CODE_CHOICES, default=DEFAULT_CURRENCY)- event_retention_months = serializers.IntegerField(- read_only=True,- help_text=(- "The team's events data retention window in months (plan-derived, synced from billing). When retention "- "enforcement is active for the team, queries do not return events older than this many months. "- "Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog "- "support can change it unless your organization is on the enterprise plan. Background and discussion: "- "https://github.com/PostHog/posthog/issues/17031"- ),- )- events_retention_enforced = serializers.SerializerMethodField(- help_text=(- "Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: "- "neither you nor PostHog support can turn enforcement off, and the retention window itself only "- "changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031"- )- )class Meta:model = Team@@ -1257,8 +1239,6 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin"product_intents","managed_viewsets","available_setup_task_ids",- "event_retention_months",- "events_retention_enforced",)read_only_fields = (@@ -1314,11 +1294,6 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixinself._group_types_cache = group_typesreturn group_types- @extend_schema_field(serializers.BooleanField())- @tracer.start_as_current_span("team_serializer.events_retention_enforced")- def get_events_retention_enforced(self, team: Team) -> bool:- return should_enforce_events_retention(team.id)-@tracer.start_as_current_span("team_serializer.live_events_token")def get_live_events_token(self, team: Team) -> str | None:request = self.context.get("request")diff --git a/products/desktop/packages/api-client/src/generated.ts b/products/desktop/packages/api-client/src/generated.tsindex f4df2f128d5f..21d9d98498ee 100644--- a/products/desktop/packages/api-client/src/generated.ts+++ b/products/desktop/packages/api-client/src/generated.ts@@ -18903,14 +18903,6 @@ export namespace Schemas {web_analytics_pre_aggregated_tables_enabled?:| (boolean | null)| undefined;- /**- * The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog support can change it unless your organization is on the enterprise plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031- */- event_retention_months: number;- /**- * Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: neither you nor PostHog support can turn enforcement off, and the retention window itself only changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031- */- events_retention_enforced: boolean;};/*** * `exact` - exactdiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 14a8df71bfe7..22c796fa5079 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -68779,10 +68779,6 @@ export namespace Schemas {onboarding_tasks?: unknown;/** @nullable */web_analytics_pre_aggregated_tables_enabled?: boolean | null;- /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog support can change it unless your organization is on the enterprise plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly event_retention_months?: number;- /** Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: neither you nor PostHog support can turn enforcement off, and the retention window itself only changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly events_retention_enforced?: boolean;}export interface PatchedProjectSecretAPIKey {@@ -73130,10 +73126,6 @@ export namespace Schemas {onboarding_tasks?: unknown;/** @nullable */web_analytics_pre_aggregated_tables_enabled?: boolean | null;- /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. Read-only: this value follows your plan's data retention entitlement, so neither you nor PostHog support can change it unless your organization is on the enterprise plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly event_retention_months: number;- /** Whether events data retention is currently enforced for this team (cohort/flag gated). Read-only: neither you nor PostHog support can turn enforcement off, and the retention window itself only changes with your plan. Background and discussion: https://github.com/PostHog/posthog/issues/17031 */- readonly events_retention_enforced: boolean;}/**