: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
feat(data-warehouse): evaluate duckgres-batch-sink flag locally with group properties (#65586)
Eric Duong04391ef28a12
diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.pyindex a3c501451b3d..437b03089841 100644--- a/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py@@ -30,6 +30,11 @@ def duckgres_sink_team_ids() -> list[int] | None:Runs sync (Django ORM + flag evaluation); call via sync_to_async from theconsumer. Raises on app-DB errors — the caller keeps its previous cachedset so a transient app-DB blip doesn't blind the sink.++ The flag is evaluated only-locally (no per-team network round-trip) with the+ org/project group properties supplied inline, matching the data-warehouse-scene+ gate and the legacy copy-workflow gate. A team that can't be resolved locally+ evaluates falsy and is skipped (safe direction)."""if is_dev_mode():return None@@ -52,6 +57,11 @@ def duckgres_sink_team_ids() -> list[int] | None:DUCKGRES_BATCH_SINK_FLAG,str(team_uuid),groups={"organization": str(org_id), "project": str(team_id)},+ group_properties={+ "organization": {"id": str(org_id)},+ "project": {"id": str(team_id)},+ },+ only_evaluate_locally=True,send_feature_flag_events=False,):enabled.append(team_id)diff --git a/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.py b/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.pynew file mode 100644index 000000000000..1c5503e15a6f--- /dev/null+++ b/posthog/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.py@@ -0,0 +1,51 @@+import pytest+from unittest.mock import MagicMock, patch++from posthog.ducklake.models import DuckgresServer+from posthog.models import Organization, Team+from posthog.temporal.data_imports.pipelines.pipeline_v3.duckgres import enablement+from posthog.temporal.data_imports.pipelines.pipeline_v3.duckgres.enablement import duckgres_sink_team_ids++[email protected](enablement, "is_dev_mode", return_value=False)[email protected](enablement.posthoganalytics, "feature_enabled")+def test_duckgres_sink_flag_evaluated_locally_with_group_properties(+ mock_feature_enabled: MagicMock, _mock_dev: MagicMock+) -> None:+ """The duckgres-batch-sink gate must mirror the data-warehouse-scene call:+ org+project group properties supplied inline and only-local evaluation."""+ org = Organization.objects.create(name="Org")+ team = Team.objects.create(organization=org)+ DuckgresServer.objects.create(organization=org, host="h", username="root", password="x")+ mock_feature_enabled.return_value = True++ assert duckgres_sink_team_ids() == [team.id]++ mock_feature_enabled.assert_called_once_with(+ "duckgres-batch-sink",+ str(team.uuid),+ groups={"organization": str(org.id), "project": str(team.id)},+ group_properties={+ "organization": {"id": str(org.id)},+ "project": {"id": str(team.id)},+ },+ only_evaluate_locally=True,+ send_feature_flag_events=False,+ )++[email protected](enablement, "is_dev_mode", return_value=False)[email protected](enablement.posthoganalytics, "feature_enabled")+def test_duckgres_sink_skips_team_when_flag_unresolved_locally(+ mock_feature_enabled: MagicMock, _mock_dev: MagicMock+) -> None:+ """only_evaluate_locally returns None when the flag can't be resolved; that+ falsy value must skip the team, never claim it."""+ org = Organization.objects.create(name="Org")+ Team.objects.create(organization=org)+ DuckgresServer.objects.create(organization=org, host="h", username="root", password="x")+ mock_feature_enabled.return_value = None++ assert duckgres_sink_team_ids() == []