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(flags): add internal TeamFeatureFlagsConfig team extension (#68051)

Phil Haack289dd89c28a0
diff --git a/.github/scripts/check-idor-model-coverage.py b/.github/scripts/check-idor-model-coverage.py
index 9ca1bbbd8aa0..f3c3d503beed 100644
--- a/.github/scripts/check-idor-model-coverage.py
+++ b/.github/scripts/check-idor-model-coverage.py
@@ -173,6 +173,7 @@ def get_scoped_models() -> tuple[dict[str, set[str]], set[str], set[str], set[st
"TeamDefaultEvaluationContext",
"TeamDataWarehouseConfig",
"TeamExperimentsConfig",
+ "TeamFeatureFlagsConfig",
"TeamLogsConfig",
"TeamMarketingAnalyticsConfig",
"TeamRevenueAnalyticsConfig",
diff --git a/products/feature_flags/backend/migrations/0008_team_feature_flags_config.py b/products/feature_flags/backend/migrations/0008_team_feature_flags_config.py
new file mode 100644
index 000000000000..a255818cfa97
--- /dev/null
+++ b/products/feature_flags/backend/migrations/0008_team_feature_flags_config.py
@@ -0,0 +1,30 @@
+# Generated by Django 5.2.14 on 2026-07-02 20:04
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("feature_flags", "0007_clean_invalid_multivariate_filters"),
+ ("posthog", "1247_oauthaccesstoken_token_idx"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="TeamFeatureFlagsConfig",
+ fields=[
+ (
+ "team",
+ models.OneToOneField(
+ db_constraint=False,
+ on_delete=django.db.models.deletion.CASCADE,
+ primary_key=True,
+ serialize=False,
+ to="posthog.team",
+ ),
+ ),
+ ("minimal_flag_called_events", models.BooleanField(default=False)),
+ ],
+ ),
+ ]
diff --git a/products/feature_flags/backend/migrations/max_migration.txt b/products/feature_flags/backend/migrations/max_migration.txt
index 940cf879f893..817cf71810e2 100644
--- a/products/feature_flags/backend/migrations/max_migration.txt
+++ b/products/feature_flags/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0007_clean_invalid_multivariate_filters
+0008_team_feature_flags_config
diff --git a/products/feature_flags/backend/models/__init__.py b/products/feature_flags/backend/models/__init__.py
index 91f70efdb0ea..09b8ba14bddc 100644
--- a/products/feature_flags/backend/models/__init__.py
+++ b/products/feature_flags/backend/models/__init__.py
@@ -2,6 +2,7 @@ from .evaluation_context import EvaluationContext, FeatureFlagEvaluationContext,
from .feature_flag import FeatureFlag, FeatureFlagDashboards, FeatureFlagHashKeyOverride, FeatureFlagOverride
from .scheduled_change import ScheduledChange
from .team_feature_flag_defaults_config import TeamFeatureFlagDefaultsConfig
+from .team_feature_flags_config import TeamFeatureFlagsConfig
__all__ = [
"EvaluationContext",
@@ -12,5 +13,6 @@ __all__ = [
"FeatureFlagOverride",
"ScheduledChange",
"TeamFeatureFlagDefaultsConfig",
+ "TeamFeatureFlagsConfig",
"TeamDefaultEvaluationContext",
]
diff --git a/products/feature_flags/backend/models/team_feature_flags_config.py b/products/feature_flags/backend/models/team_feature_flags_config.py
new file mode 100644
index 000000000000..4c9d3bd9e7f6
--- /dev/null
+++ b/products/feature_flags/backend/models/team_feature_flags_config.py
@@ -0,0 +1,30 @@
+import logging
+
+from django.db import models
+
+from posthog.models.team.extensions import register_team_extension_signal
+
+logger = logging.getLogger(__name__)
+
+
+class TeamFeatureFlagsConfig(models.Model):
+ """Internal-only team-level feature flags behavior settings.
+
+ Never expose this model through a serializer, API endpoint, or settings UI —
+ it gates server-controlled behavior rollouts, not customer preferences.
+ Sanctioned writers: the team-creation signal below, get_or_create_team_extension,
+ and management commands.
+ """
+
+ # db_constraint=False: a real FK constraint would take a SHARE ROW EXCLUSIVE
+ # lock on posthog_team (a hot table) while migrating.
+ team = models.OneToOneField("posthog.Team", on_delete=models.CASCADE, primary_key=True, db_constraint=False)
+
+ # Allows SDKs to send slim $feature_flag_called events for flags without a
+ # linked experiment. False = full events (legacy behavior). Stays False for
+ # all teams, new or existing, until SDKs support the slim event shape;
+ # flip via management command once they do.
+ minimal_flag_called_events = models.BooleanField(default=False)
+
+
+register_team_extension_signal(TeamFeatureFlagsConfig, logger=logger)
diff --git a/products/feature_flags/backend/test/test_team_feature_flags_config.py b/products/feature_flags/backend/test/test_team_feature_flags_config.py
new file mode 100644
index 000000000000..cb247a7c2794
--- /dev/null
+++ b/products/feature_flags/backend/test/test_team_feature_flags_config.py
@@ -0,0 +1,21 @@
+from posthog.test.base import BaseTest
+
+from posthog.models.team import Team
+from posthog.models.team.extensions import get_or_create_team_extension
+
+from products.feature_flags.backend.models import TeamFeatureFlagsConfig
+
+
+class TestTeamFeatureFlagsConfig(BaseTest):
+ def test_new_team_config_defaults_to_disabled(self):
+ team = Team.objects.create(organization=self.organization, name="New Team")
+
+ config = TeamFeatureFlagsConfig.objects.get(team=team)
+ self.assertFalse(config.minimal_flag_called_events)
+
+ def test_lazily_created_config_defaults_to_disabled(self):
+ # A team without a row models a legacy team predating this extension.
+ TeamFeatureFlagsConfig.objects.filter(team=self.team).delete()
+
+ config = get_or_create_team_extension(self.team, TeamFeatureFlagsConfig)
+ self.assertFalse(config.minimal_flag_called_events)