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.

fix(customer-analytics): enable warehouse properties on self-hosted (#116010)

Tom Owerse21b746a8183
diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
index 0e5a28cc7904..d7107047efc3 100644
--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts
@@ -163,6 +163,18 @@ describe('projectTreeDataLogic', () => {
expect(paths).toEqual(['Session replay'])
})
+ it('shows Warehouse properties in Data when its persisted feature flag is enabled', () => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES]: false })
+
+ const dataRootWithoutFlag = logic.values.getStaticTreeItems('', false).find((item) => item.id === 'data://')
+ expect(dataRootWithoutFlag?.children?.some((item) => item.record?.path === 'Warehouse properties')).toBe(false)
+
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES]: true })
+
+ const dataRootWithFlag = logic.values.getStaticTreeItems('', false).find((item) => item.id === 'data://')
+ expect(dataRootWithFlag?.children?.some((item) => item.record?.path === 'Warehouse properties')).toBe(true)
+ })
+
it('handles null unfiled item responses', async () => {
jest.mocked(api.fileSystem.unfiled).mockResolvedValueOnce(null)
await expectLogic(logic, () => {
diff --git a/frontend/src/lib/logic/featureFlagLogic.test.ts b/frontend/src/lib/logic/featureFlagLogic.test.ts
index 71aa1c39f5aa..53bed0a7df17 100644
--- a/frontend/src/lib/logic/featureFlagLogic.test.ts
+++ b/frontend/src/lib/logic/featureFlagLogic.test.ts
@@ -1,8 +1,11 @@
import posthog from 'posthog-js'
+import { FEATURE_FLAGS } from 'lib/constants'
+
import { initKeaTests } from '~/test/init'
+import type { AppContext } from '~/types'
-import { areClientFeatureFlagsHonored, featureFlagLogic } from './featureFlagLogic'
+import { areClientFeatureFlagsHonored, featureFlagLogic, getPersistedFeatureFlags } from './featureFlagLogic'
describe('featureFlagLogic', () => {
describe('areClientFeatureFlagsHonored', () => {
@@ -24,6 +27,18 @@ describe('featureFlagLogic', () => {
})
})
+ describe('getPersistedFeatureFlags', () => {
+ it('maps server-persisted flags to the enabled frontend baseline', () => {
+ const appContext = {
+ persisted_feature_flags: [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES],
+ } as AppContext
+
+ expect(getPersistedFeatureFlags(appContext)).toEqual({
+ [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES]: true,
+ })
+ })
+ })
+
describe('receivedFeatureFlags', () => {
afterEach(() => {
delete (posthog as any).config
diff --git a/frontend/src/lib/logic/featureFlagLogic.ts b/frontend/src/lib/logic/featureFlagLogic.ts
index 4927a6fb5144..5d6a116b97cd 100644
--- a/frontend/src/lib/logic/featureFlagLogic.ts
+++ b/frontend/src/lib/logic/featureFlagLogic.ts
@@ -35,7 +35,7 @@ function notifyFlagIfNeeded(flag: string, flagState: string | boolean | undefine
}
}
-function getPersistedFeatureFlags(appContext: AppContext | undefined = getAppContext()): FeatureFlagsSet {
+export function getPersistedFeatureFlags(appContext: AppContext | undefined = getAppContext()): FeatureFlagsSet {
const persistedFeatureFlags = appContext?.persisted_feature_flags || []
// The server sends a list of enabled flag keys (each maps to `true`). Storybook can
// instead supply a record so a story can pin a multivariate variant (e.g. an
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.py
index 609ec1a88867..fe96fa3eab6e 100644
--- a/posthog/api/sharing.py
+++ b/posthog/api/sharing.py
@@ -15,7 +15,6 @@ from django.views.decorators.clickjacking import xframe_options_exempt
import jwt
import structlog
-import posthoganalytics
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schema_field
from pydantic import BaseModel
@@ -57,7 +56,7 @@ from posthog.scopes import APIScopeObject
from posthog.session_recordings.session_recording_api import SessionRecordingSerializer
from posthog.shared_link_user import SharedLinkUser
from posthog.user_permissions import UserPermissions
-from posthog.utils import get_ip_address, render_template
+from posthog.utils import get_ip_address, get_persisted_feature_flags_for_app_context, render_template
from posthog.views import preflight_check
from products.access_control.backend.facade.user_access_control import (
@@ -83,7 +82,6 @@ from products.exports.backend.models.exported_asset import (
get_content_response,
)
from products.exports.backend.url_security import is_heatmap_url_allowed
-from products.feature_flags.backend.persisted_flags import get_dynamic_persisted_feature_flags
from products.notebooks.backend.facade.content import extract_inline_query_nodes, filter_notebook_content_for_sharing
from products.notebooks.backend.models import Notebook
from products.notebooks.backend.presentation.views.notebook import NotebookSerializer
@@ -328,9 +326,7 @@ def build_shared_app_context(team: Team, request: Request) -> dict[str, Any]:
"suggested_users_with_access": None,
"commit_sha": get_git_commit_short(),
"livestream_host": settings.LIVESTREAM_HOST,
- "persisted_feature_flags": get_dynamic_persisted_feature_flags(
- posthoganalytics.feature_flag_definitions(), settings.PERSISTED_FEATURE_FLAGS
- ),
+ "persisted_feature_flags": get_persisted_feature_flags_for_app_context(),
"anonymous": True,
}
diff --git a/posthog/settings/feature_flags.py b/posthog/settings/feature_flags.py
index 4c8cb0d975eb..035e3c10c5dd 100644
--- a/posthog/settings/feature_flags.py
+++ b/posthog/settings/feature_flags.py
@@ -12,6 +12,20 @@ from posthog.settings.utils import get_from_env, get_list, get_set, str_to_bool
# NOTE: This only affects the frontend, the same FFs will still be considered disabled on the backend
PERSISTED_FEATURE_FLAGS = get_list(os.getenv("PERSISTED_FEATURE_FLAGS", ""))
+# Frontend flags for the warehouse person properties feature. Non-cloud deployments do not take part in
+# Cloud rollout evaluation, so these join the persisted baseline unless the
+# WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED kill switch is off.
+WAREHOUSE_PERSON_PROPERTIES_PERSISTED_FEATURE_FLAGS = ("warehouse-person-properties",)
+
+# Self-hosted instances can't reach Cloud's staged-rollout flag service, so
+# `person_properties_flag_enabled` (products/customer_analytics/backend/logic/person_property_projection.py)
+# skips it there and enables warehouse-backed person/group properties directly. This is the
+# self-hosted equivalent of that Cloud flag: an operator kill switch, checked via env var instead
+# of a network call, in case the feature needs to be turned off on a given self-hosted instance.
+WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED: bool = get_from_env(
+ "WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED", True, type_cast=str_to_bool
+)
+
# Encryption keys for remote-config feature flag payloads, kept separate from
# Temporal's keys (posthog/settings/temporal.py) so the two rotate independently.
# An ordered list: the first key encrypts new payloads, every key can decrypt. That
diff --git a/posthog/test/test_get_context_for_template.py b/posthog/test/test_get_context_for_template.py
index 50edf53bc442..c92824b16e2f 100644
--- a/posthog/test/test_get_context_for_template.py
+++ b/posthog/test/test_get_context_for_template.py
@@ -9,17 +9,81 @@ from django.contrib.auth.models import AnonymousUser
from django.contrib.sessions.middleware import SessionMiddleware
from django.http import HttpResponse
from django.template.loader import render_to_string
-from django.test import RequestFactory
+from django.test import RequestFactory, SimpleTestCase
from parameterized import parameterized
from posthog.api.tagged_item import set_tags_on_object
from posthog.models import UserHomeSettings
from posthog.stable_chunks import StableChunks
-from posthog.utils import get_context_for_template
+from posthog.utils import get_context_for_template, get_persisted_feature_flags_for_app_context
from products.conversations.backend.services.identity import IDENTITY_CLAIM_MAX_AGE_SECONDS
+
+class TestPersistedFeatureFlagsForAppContext(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("enabled", True, [], [], ["warehouse-person-properties"]),
+ ("disabled", False, [], [], []),
+ (
+ "disabled_explicit",
+ False,
+ ["warehouse-person-properties", "other-feature"],
+ [],
+ ["other-feature"],
+ ),
+ (
+ "disabled_dynamic",
+ False,
+ ["other-feature"],
+ [
+ {
+ "key": "warehouse-person-properties",
+ "active": True,
+ "filters": {"groups": [{"rollout_percentage": 100}]},
+ }
+ ],
+ ["other-feature"],
+ ),
+ ]
+ )
+ @mock.patch("posthog.utils.posthoganalytics.feature_flag_definitions")
+ def test_self_hosted_context_respects_operator_setting(
+ self, _name, enabled, static_flags, definitions, expected, mock_definitions
+ ):
+ mock_definitions.return_value = definitions
+ with self.settings(
+ CLOUD_DEPLOYMENT=None,
+ DEBUG=False,
+ PERSISTED_FEATURE_FLAGS=static_flags,
+ WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED=enabled,
+ ):
+ assert get_persisted_feature_flags_for_app_context() == expected
+
+ @parameterized.expand(
+ [
+ ("without_explicit_flag", [], []),
+ (
+ "with_explicit_flag",
+ ["warehouse-person-properties"],
+ ["warehouse-person-properties"],
+ ),
+ ]
+ )
+ @mock.patch("posthog.utils.posthoganalytics.feature_flag_definitions", return_value=[])
+ def test_cloud_context_does_not_include_non_cloud_persisted_flags(
+ self, _name, static_flags, expected, _definitions
+ ):
+ with self.settings(
+ CLOUD_DEPLOYMENT="US",
+ DEBUG=False,
+ PERSISTED_FEATURE_FLAGS=static_flags,
+ WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED=False,
+ ):
+ assert get_persisted_feature_flags_for_app_context() == expected
+
+
STABLE_CHUNKS = StableChunks(
imports={"@c/eAAAA": "static/index-S0000000000.js"},
preload_js_urls=("static/index-S0000000000.js",),
@@ -49,7 +113,7 @@ class TestGetContextForTemplate(APIBaseTest):
"js_url": "http://localhost:8234",
"opt_out_capture": False,
"posthog_app_context": {
- "persisted_feature_flags": ["the_persisted_flags"],
+ "persisted_feature_flags": ["the_persisted_flags", "warehouse-person-properties"],
"anonymous": False,
"run_mode": "LOCAL",
},
@@ -98,7 +162,14 @@ class TestGetContextForTemplate(APIBaseTest):
@parameterized.expand(
[
- ("configured", {"pathname": "/dashboard/42", "pinned": True, "title": "Default dashboard"}),
+ (
+ "configured",
+ {
+ "pathname": "/dashboard/42",
+ "pinned": True,
+ "title": "Default dashboard",
+ },
+ ),
("not_configured", None),
("empty_is_cleared", {}),
]
diff --git a/posthog/utils.py b/posthog/utils.py
index 5c9717e33e4c..781ac5af9f4a 100644
--- a/posthog/utils.py
+++ b/posthog/utils.py
@@ -497,6 +497,17 @@ def get_context_for_template(
return _build_template_context(template_name, request, context, team_for_public_context)
+def get_persisted_feature_flags_for_app_context() -> list[str]:
+ static_keys = list(settings.PERSISTED_FEATURE_FLAGS)
+ non_cloud = not is_cloud()
+ if non_cloud and settings.WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED:
+ static_keys = [*static_keys, *settings.WAREHOUSE_PERSON_PROPERTIES_PERSISTED_FEATURE_FLAGS]
+ flags = get_dynamic_persisted_feature_flags(posthoganalytics.feature_flag_definitions(), static_keys)
+ if non_cloud and not settings.WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED:
+ return [flag for flag in flags if flag not in settings.WAREHOUSE_PERSON_PROPERTIES_PERSISTED_FEATURE_FLAGS]
+ return flags
+
+
def _build_template_context(
template_name: str,
request: HttpRequest,
@@ -572,9 +583,7 @@ def _build_template_context(
context["js_url"] = get_js_url(request)
posthog_app_context: dict[str, Any] = {
- "persisted_feature_flags": get_dynamic_persisted_feature_flags(
- posthoganalytics.feature_flag_definitions(), settings.PERSISTED_FEATURE_FLAGS
- ),
+ "persisted_feature_flags": get_persisted_feature_flags_for_app_context(),
"anonymous": not request.user or not request.user.is_authenticated,
"run_mode": run_mode().value,
}
diff --git a/products/customer_analytics/backend/logic/person_property_projection.py b/products/customer_analytics/backend/logic/person_property_projection.py
index 75c25262c1b4..200ff2a81d79 100644
--- a/products/customer_analytics/backend/logic/person_property_projection.py
+++ b/products/customer_analytics/backend/logic/person_property_projection.py
@@ -11,8 +11,11 @@ once a binding is confirmed to have enabled person sources, so unconfigured tabl
vast majority of runs) never pay a flag-service call.
"""
+from django.conf import settings
+
import posthoganalytics
+from posthog.cloud_utils import is_cloud
from posthog.exceptions_capture import capture_exception
from posthog.models import Team
@@ -36,6 +39,9 @@ def person_properties_flag_enabled(team_id: int) -> bool:
organization_id = str(Team.objects.only("organization_id").get(id=team_id).organization_id)
except Team.DoesNotExist:
return False
+ if not is_cloud():
+ # Self-hosted has no staged rollout to consult; respect the operator's kill switch instead.
+ return settings.WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED
try:
return bool(
posthoganalytics.feature_enabled(
diff --git a/products/customer_analytics/backend/logic/person_property_projection_test.py b/products/customer_analytics/backend/logic/person_property_projection_test.py
index 87de041c60a3..8d5dcf733a9f 100644
--- a/products/customer_analytics/backend/logic/person_property_projection_test.py
+++ b/products/customer_analytics/backend/logic/person_property_projection_test.py
@@ -1,9 +1,12 @@
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase, override_settings
+
from parameterized import parameterized, parameterized_class
from products.customer_analytics.backend.logic.person_property_projection import (
+ person_properties_flag_enabled,
person_property_projection,
person_property_sync_sources,
)
@@ -15,6 +18,64 @@ from products.warehouse_sources.backend.models.external_data_schema import Exter
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
+class PersonPropertyRolloutFlagTest(SimpleTestCase):
+ @staticmethod
+ def _set_team(only):
+ only.return_value.get.return_value.organization_id = 123
+
+ @patch("products.customer_analytics.backend.logic.person_property_projection.Team.objects.only")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.posthoganalytics.feature_enabled")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.is_cloud", return_value=False)
+ def test_self_hosted_instances_do_not_depend_on_the_rollout_flag(self, is_cloud, feature_enabled, only):
+ self._set_team(only)
+
+ assert person_properties_flag_enabled(1) is True
+ is_cloud.assert_called_once_with()
+ feature_enabled.assert_not_called()
+
+ @patch("products.customer_analytics.backend.logic.person_property_projection.Team.objects.only")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.posthoganalytics.feature_enabled")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.is_cloud", return_value=False)
+ @override_settings(WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED=False)
+ def test_self_hosted_operator_kill_switch_disables_the_feature(self, is_cloud, feature_enabled, only):
+ self._set_team(only)
+
+ assert person_properties_flag_enabled(1) is False
+ feature_enabled.assert_not_called()
+
+ @patch("products.customer_analytics.backend.logic.person_property_projection.Team.objects.only")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.posthoganalytics.feature_enabled")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.is_cloud", return_value=True)
+ def test_cloud_instances_use_the_rollout_flag(self, is_cloud, feature_enabled, only):
+ self._set_team(only)
+ feature_enabled.return_value = True
+
+ assert person_properties_flag_enabled(1) is True
+ feature_enabled.assert_called_once_with(
+ "warehouse-person-properties",
+ "123",
+ groups={"organization": "123"},
+ only_evaluate_locally=False,
+ send_feature_flag_events=False,
+ )
+
+ feature_enabled.reset_mock()
+ feature_enabled.return_value = False
+ assert person_properties_flag_enabled(1) is False
+
+ @patch("products.customer_analytics.backend.logic.person_property_projection.Team.objects.only")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.capture_exception")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.posthoganalytics.feature_enabled")
+ @patch("products.customer_analytics.backend.logic.person_property_projection.is_cloud", return_value=True)
+ def test_cloud_flag_errors_fail_closed(self, is_cloud, feature_enabled, capture_exception, only):
+ self._set_team(only)
+ error = RuntimeError("flag service unavailable")
+ feature_enabled.side_effect = error
+
+ assert person_properties_flag_enabled(1) is False
+ capture_exception.assert_called_once_with(error)
+
+
# Both binding kinds run every case: the resolvers pick the filter column from the binding, and picking
# the wrong one leaves a configured source silently never syncing.
@parameterized_class(("binding_kind",), [("schema",), ("saved_query",)])
diff --git a/products/customer_analytics/backend/test/test_views.py b/products/customer_analytics/backend/test/test_views.py
index 2c69b694ba59..edca3f4d1fc7 100644
--- a/products/customer_analytics/backend/test/test_views.py
+++ b/products/customer_analytics/backend/test/test_views.py
@@ -7,6 +7,7 @@ from posthog.test.base import APIBaseTest
from unittest.mock import MagicMock, patch
from django.apps import apps
+from django.test import override_settings
from django.utils import timezone
from parameterized import parameterized
@@ -2556,9 +2557,12 @@ class TestCustomPropertySourceViewSet(APIBaseTest):
return created.json()["id"]
@patch("posthoganalytics.feature_enabled", return_value=False)
+ @override_settings(WAREHOUSE_PERSON_PROPERTIES_ENABLED_SELF_HOSTED=False)
def test_person_source_actions_are_flag_gated(self, _flag):
# Regression: sync/backfill must 400 when WAREHOUSE_PERSON_PROPERTIES is off. The gate lives in
# the facade; a viewset refactor that dropped it would ship an ungated (billable) trigger.
+ # Both the Cloud rollout flag (mocked False above) and its self-hosted kill-switch equivalent
+ # are turned off here so this holds regardless of which code path the test runs under.
source_id = self._create_person_source()
for action in ("sync", "backfill"):
response = self.client.post(f"{self.endpoint}{source_id}/{action}/")
diff --git a/products/customer_analytics/frontend/scenes/WarehousePropertiesScene/WarehousePropertiesScene.test.tsx b/products/customer_analytics/frontend/scenes/WarehousePropertiesScene/WarehousePropertiesScene.test.tsx
new file mode 100644
index 000000000000..2dbb7677246b
--- /dev/null
+++ b/products/customer_analytics/frontend/scenes/WarehousePropertiesScene/WarehousePropertiesScene.test.tsx
@@ -0,0 +1,49 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { WarehousePropertiesScene } from './WarehousePropertiesScene'
+
+jest.mock('../CustomerAnalyticsConfigurationScene/account/WarehousePersonPropertiesSetting', () => ({
+ WarehousePersonPropertiesSetting: () => <div>Person warehouse property settings</div>,
+ WarehouseGroupPropertiesSetting: () => <div>Group warehouse property settings</div>,
+}))
+
+describe('WarehousePropertiesScene', () => {
+ let unmountFeatureFlagLogic: () => void
+
+ beforeEach(() => {
+ window.localStorage.clear()
+ initKeaTests()
+ unmountFeatureFlagLogic = featureFlagLogic.mount()
+ })
+
+ afterEach(() => {
+ cleanup()
+ unmountFeatureFlagLogic()
+ window.localStorage.clear()
+ })
+
+ it('returns Not Found when the feature flag is disabled', () => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES]: false })
+
+ render(<WarehousePropertiesScene />)
+
+ expect(screen.getByText("Warehouse properties isn't available for this project yet.")).toBeInTheDocument()
+ expect(screen.queryByText('Person warehouse property settings')).not.toBeInTheDocument()
+ })
+
+ it('allows direct access when the persisted feature flag is enabled', () => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.WAREHOUSE_PERSON_PROPERTIES]: true })
+
+ render(<WarehousePropertiesScene />)
+
+ expect(screen.queryByText("Warehouse properties isn't available for this project yet.")).not.toBeInTheDocument()
+ expect(screen.getByText('Person warehouse property settings')).toBeInTheDocument()
+ })
+})