: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(data-warehouse): finish control-plane state cutover (#73982)
Benjamin Knofe-Viderb13a513c0ac2
diff --git a/.test_durations b/.test_durationsindex 52a62e3baac1..c9372919d77e 100644--- a/.test_durations+++ b/.test_durations@@ -6884,7 +6884,6 @@"posthog/admin/test_duckgres_server_admin.py::TestDuckgresServerAdminProvision::test_provision_post_calls_managed_warehouse_bypassing_flag": 0.09388291300001583,"posthog/admin/test_duckgres_server_admin.py::TestDuckgresServerAdminProvision::test_provision_rejects_team_org_mismatch": 0.07153678199995284,"posthog/admin/test_duckgres_server_admin.py::TestDuckgresServerAdminProvision::test_provision_surfaces_helper_error": 0.0505722269999751,- "posthog/admin/test_duckgres_server_team_admin.py::TestDuckgresServerTeamAdmin::test_table_suffix_is_readonly": 0.06348898999999619,"posthog/admin/test_ducklake_backfill_admin.py::TestDuckLakeBackfillAdmin::test_table_suffix_is_readonly": 0.24140338600000177,"posthog/admin/test_email_mfa_global_disable_admin.py::TestEmailMFAGlobalDisableAdmin::test_non_staff_is_forbidden": 0.08197483399999328,"posthog/admin/test_email_mfa_global_disable_admin.py::TestEmailMFAGlobalDisableAdmin::test_reason_is_required": 0.06938648200002717,@@ -17605,9 +17604,6 @@"posthog/demo/test/test_persons_db_sync.py::TestInsertPersonDistinctIds::test_skips_distinct_ids_with_unknown_person_uuid": 0.012112034000097083,"posthog/demo/test/test_persons_db_sync.py::TestInsertPersons::test_empty_list_returns_empty_dict": 0.01,"posthog/demo/test/test_persons_db_sync.py::TestInsertPersons::test_inserts_persons_and_returns_uuid_to_pk_mapping": 0.017384295999931965,- "posthog/ducklake/test_backfill_duckgresserverteam_migration.py::TestBackfillDuckgresServerTeams::test_is_idempotent_and_preserves_existing_membership": 0.041296997000017654,- "posthog/ducklake/test_backfill_duckgresserverteam_migration.py::TestBackfillDuckgresServerTeams::test_links_existing_backfill_teams_to_their_org_server": 0.08684092499981944,- "posthog/ducklake/test_backfill_duckgresserverteam_migration.py::TestBackfillDuckgresServerTeams::test_skips_teams_whose_org_has_no_server": 0.03462163600011081,"posthog/ducklake/test_client.py::TestCompileHogQLToDuckLakeSQL::test_substitutes_variable_placeholders": 0.19131967699991037,"posthog/ducklake/test_client.py::TestDuckLakeModelRedirect::test_materialized_model_resolves_to_ducklake_table_not_s3": 0.22602785700007644,"posthog/ducklake/test_client.py::TestDuckLakeModelRedirect::test_source_table_resolves_to_ducklake_table_not_s3": 0.2372076780000043,diff --git a/posthog/dags/README_DUCKLINGS.md b/posthog/dags/README_DUCKLINGS.mdindex 2e348651b0c0..81dcecb8da8c 100644--- a/posthog/dags/README_DUCKLINGS.md+++ b/posthog/dags/README_DUCKLINGS.md@@ -5,8 +5,8 @@ This document describes the Dagster jobs and sensors for backfilling ClickHouse## Architecture```text-DuckgresServer + DuckgresServerTeam (Django models)- │ team_id → org's DuckgresServer (connection + bucket); DuckgresServerTeam gates enablement+DuckgresServer (Django model) + control-plane team rows+ │ DuckgresServer stores the org connection; control-plane rows gate each team's enablement▼ClickHouse (events/person tables)│ export via s3() - bucket policy allows ClickHouse EC2 role@@ -132,9 +132,9 @@ class DucklingBackfillConfig:## Adding a New Duckling-1. Provision (or create) the org's `DuckgresServer` (typically via the Django admin- "Provision managed warehouse" action, which also records the team's- `DuckgresServerTeam`). The relevant fields are:+1. Provision the org's managed warehouse, typically with the Django admin+ "Provision managed warehouse" action. This creates the org's `DuckgresServer`+ connection record and the first control-plane team row. The relevant local fields are:- `organization`: the org that owns the warehouse- `bucket` / `bucket_region`: S3 bucket name and AWS region- `catalog_host` / `catalog_database` / `catalog_username` / `catalog_password`: the@@ -142,9 +142,10 @@ class DucklingBackfillConfig:Ensure the runtime IAM role can read from and write to the configured S3 bucket.-2. Enable the team's backfill by creating its `DuckgresServerTeam` row with- `backfill_enabled=True` (the provision / enable-backfill admin actions do this). The- discovery sensor will then pick up the team on its next run. The enablement flow also creates a+2. Enable another team's backfill with the "Enable warehouse backfill for a team" admin+ action or the managed warehouse onboarding API. This creates the control-plane team row+ with backfill enabled. The discovery sensor will pick up the team on its next run.+ The enablement flow also creates amanaged Postgres live-query connection with a distinct Duckgres reader for the team. Once thewarehouse is ready, background schema discovery exposes every table in the team's event/person,data-import, team, and modeled-data namespaces in the SQL editor. Duckgres enforces read-only@@ -181,7 +182,8 @@ If multiple partitions for the same team run concurrently, they may race to crea- **Job definition**: `posthog/dags/events_backfill_to_duckling.py`- **Tests**: `posthog/dags/test_events_backfill_to_duckling.py`- **Dagster registration**: `posthog/dags/locations/data_stack.py`-- **DuckgresServer / DuckgresServerTeam models**: `posthog/ducklake/models.py`+- **DuckgresServer model**: `posthog/ducklake/models.py`+- **Control-plane team state**: `posthog/ducklake/cp_teams.py` and `posthog/ducklake/team_state.py`## S3 Path Structurediff --git a/posthog/dags/events_backfill_to_duckling.py b/posthog/dags/events_backfill_to_duckling.pyindex 08f172fc9485..8504992c7e9b 100644--- a/posthog/dags/events_backfill_to_duckling.py+++ b/posthog/dags/events_backfill_to_duckling.py@@ -2999,7 +2999,7 @@ EVENTS_BACKFILL_TARGET_QUEUE_DEPTH = 100# budget) even when filling the queue from empty.EVENTS_BACKFILL_MAX_PARTITIONS_PER_TICK = 100# Cap on per-team earliest-event ClickHouse lookups per tick. This is the only expensive-# sensor op; it runs once per team ever, then the result is cached on the model row.+# sensor op; it runs once per team ever, then the result is cached on the control-plane team row.EVENTS_BACKFILL_MAX_EARLIEST_LOOKUPS_PER_TICK = 5# Existing installations predate the durable UI projection. Reconcile a bounded# number of historical partitions per tick so the sensor stays within its budget.diff --git a/posthog/ducklake/cp_teams.py b/posthog/ducklake/cp_teams.pyindex 62ac0ab273d1..05150c8b5efa 100644--- a/posthog/ducklake/cp_teams.py+++ b/posthog/ducklake/cp_teams.py@@ -111,24 +111,40 @@ def team_from_row(row: dict, *, organization_id: str | None = None) -> CPTeam |_cache_lock = threading.Lock()_cache: dict[tuple[str, ...], tuple[float, list[dict]]] = {}+_cache_epoch = 0+_cache_generations: dict[tuple[str, ...], int] = {}def clear_cache() -> None:"""Drop every cached CP response (for tests and operational cache busts)."""+ global _cache_epochwith _cache_lock:_cache.clear()+ _cache_epoch += 1-def _cached_rows(key: tuple[str, ...], fetch: Callable[[], list[dict] | None]) -> list[dict] | None:- """Serve `key` from the TTL cache, fetching (and caching only successes) on a miss."""+def invalidate_org_cache(organization_id: str) -> None:+ """Drop cached rows affected by a mutation to one organization's teams."""+ with _cache_lock:+ for key in (("org_teams", str(organization_id)), ("all_teams",)):+ _cache.pop(key, None)+ _cache_generations[key] = _cache_generations.get(key, 0) + 1+++def _cached_rows(+ key: tuple[str, ...], fetch: Callable[[], list[dict] | None], *, use_cache: bool = True+) -> list[dict] | None:+ """Serve `key` from the TTL cache unless the caller requires a fresh CP read."""with _cache_lock:hit = _cache.get(key)- if hit is not None and time.monotonic() - hit[0] < CACHE_TTL_SECONDS:+ if use_cache and hit is not None and time.monotonic() - hit[0] < CACHE_TTL_SECONDS:return hit[1]+ generation = (_cache_epoch, _cache_generations.get(key, 0))rows = fetch()if rows is not None:with _cache_lock:- _cache[key] = (time.monotonic(), rows)+ if generation == (_cache_epoch, _cache_generations.get(key, 0)):+ _cache[key] = (time.monotonic(), rows)return rows@@ -157,10 +173,10 @@ def _fetch_all_rows() -> list[dict] | None:return None-def list_org_teams(organization_id: str) -> list[CPTeam] | None:+def list_org_teams(organization_id: str, *, use_cache: bool = True) -> list[CPTeam] | None:"""All CP team rows of an org, or None when the control plane can't answer."""org_id = str(organization_id)- rows = _cached_rows(("org_teams", org_id), lambda: _fetch_org_rows(org_id))+ rows = _cached_rows(("org_teams", org_id), lambda: _fetch_org_rows(org_id), use_cache=use_cache)if rows is None:return Noneteams = (team_from_row(row, organization_id=org_id) for row in rows)@@ -180,9 +196,9 @@ def get_team(organization_id: str, team_id: int) -> CPTeam | None:return next((team for team in teams if team.team_id == wanted), None)-def list_member_teams() -> list[CPTeam] | None:+def list_member_teams(*, use_cache: bool = True) -> list[CPTeam] | None:"""Every CP team row across all orgs, or None when unreachable."""- rows = _cached_rows(("all_teams",), _fetch_all_rows)+ rows = _cached_rows(("all_teams",), _fetch_all_rows, use_cache=use_cache)if rows is None:return Noneteams = (team_from_row(row) for row in rows)diff --git a/posthog/ducklake/test_cp_teams.py b/posthog/ducklake/test_cp_teams.pyindex b82220e92be9..d1651d94d325 100644--- a/posthog/ducklake/test_cp_teams.py+++ b/posthog/ducklake/test_cp_teams.py@@ -114,6 +114,53 @@ class TestTTLCache:cp_teams.list_org_teams("org-1")assert mock_fetch.call_count == 2+ def test_fresh_read_bypasses_and_replaces_cached_rows(self) -> None:+ with patch(+ "posthog.ducklake.cp_teams._fetch_org_rows",+ side_effect=[[_row(team_id=1)], [_row(team_id=2, schema_name="two")]],+ ) as mock_fetch:+ first = cp_teams.list_org_teams("org-1")+ fresh = cp_teams.list_org_teams("org-1", use_cache=False)+ cached = cp_teams.list_org_teams("org-1")++ assert mock_fetch.call_count == 2+ assert first is not None and [team.team_id for team in first] == [1]+ assert fresh is not None and [team.team_id for team in fresh] == [2]+ assert cached == fresh++ def test_org_invalidation_clears_org_and_global_rows_only(self) -> None:+ with (+ patch("posthog.ducklake.cp_teams._fetch_org_rows", return_value=[_row()]) as fetch_org,+ patch("posthog.ducklake.cp_teams._fetch_all_rows", return_value=[_row()]) as fetch_all,+ ):+ cp_teams.list_org_teams("org-1")+ cp_teams.list_org_teams("org-2")+ cp_teams.list_member_teams()+ cp_teams.invalidate_org_cache("org-1")+ cp_teams.list_org_teams("org-1")+ cp_teams.list_org_teams("org-2")+ cp_teams.list_member_teams()++ assert fetch_org.call_count == 3+ assert fetch_all.call_count == 2++ def test_invalidation_during_fetch_prevents_stale_repopulation(self) -> None:+ responses = iter([[_row(team_id=1)], [_row(team_id=2, schema_name="two")]])++ def fetch_rows(_organization_id: str) -> list[dict]:+ rows = next(responses)+ if rows[0]["team_id"] == 1:+ cp_teams.invalidate_org_cache("org-1")+ return rows++ with patch("posthog.ducklake.cp_teams._fetch_org_rows", side_effect=fetch_rows) as fetch_org:+ stale = cp_teams.list_org_teams("org-1")+ fresh = cp_teams.list_org_teams("org-1")++ assert fetch_org.call_count == 2+ assert stale is not None and [team.team_id for team in stale] == [1]+ assert fresh is not None and [team.team_id for team in fresh] == [2]+def test_cache_is_keyed_per_org(self) -> None:with patch("posthog.ducklake.cp_teams._fetch_org_rows", return_value=[_row()]) as mock_fetch:cp_teams.list_org_teams("org-1")diff --git a/posthog/migrations/1277_drop_duckgresserverteam_hot_table_fks.py b/posthog/migrations/1277_drop_duckgresserverteam_hot_table_fks.pynew file mode 100644index 000000000000..6a86173bc6cf--- /dev/null+++ b/posthog/migrations/1277_drop_duckgresserverteam_hot_table_fks.py@@ -0,0 +1,39 @@+from django.db import migrations++DROP_RETAINED_TABLE_HOT_FKS = """+DO $$+DECLARE+ constraint_name text;+BEGIN+ FOR constraint_name IN+ SELECT DISTINCT constraint_record.conname+ FROM pg_constraint AS constraint_record+ JOIN pg_class AS table_record ON table_record.oid = constraint_record.conrelid+ JOIN LATERAL unnest(constraint_record.conkey) AS key_column(attnum) ON TRUE+ JOIN pg_attribute AS column_record+ ON column_record.attrelid = table_record.oid+ AND column_record.attnum = key_column.attnum+ WHERE table_record.relname = 'posthog_duckgresserverteam'+ AND table_record.relnamespace = current_schema()::regnamespace+ AND constraint_record.contype = 'f'+ AND column_record.attname IN ('team_id', 'created_by_id')+ LOOP+ EXECUTE format(+ 'ALTER TABLE posthog_duckgresserverteam DROP CONSTRAINT IF EXISTS %I',+ constraint_name+ );+ END LOOP;+END+$$;+"""+++class Migration(migrations.Migration):+ dependencies = [("posthog", "1276_untrack_legacy_provisioning_columns")]++ operations = [+ migrations.RunSQL(+ sql=DROP_RETAINED_TABLE_HOT_FKS,+ reverse_sql=migrations.RunSQL.noop,+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex 95c8c2eded81..048bf8e2dd06 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1276_untrack_legacy_provisioning_columns+1277_drop_duckgresserverteam_hot_table_fksdiff --git a/posthog/templates/admin/posthog/duckgres_server/deprovision_confirm.html b/posthog/templates/admin/posthog/duckgres_server/deprovision_confirm.htmlindex 57f0b15a9b93..5025185a2d5a 100644--- a/posthog/templates/admin/posthog/duckgres_server/deprovision_confirm.html+++ b/posthog/templates/admin/posthog/duckgres_server/deprovision_confirm.html@@ -5,8 +5,8 @@<p><strong>Deprovision the managed warehouse for organization <code>{{ server.organization_id }}</code>?</strong></p><p>This makes a real control-plane <code>/deprovision</code> call for server <code>{{ server.host }}</code>and tears down the org's managed warehouse. <strong>This cannot be undone.</strong> The-<code>DuckgresServer</code> / <code>DuckgresServerTeam</code> rows are-left in place for the record — delete them separately if needed.</p>+control-plane team rows are removed. The local <code>DuckgresServer</code> connection record is+left in place for the record; delete it separately if needed.</p><form method="post">{% csrf_token %}diff --git a/posthog/templates/admin/posthog/duckgres_server/enable_backfill_form.html b/posthog/templates/admin/posthog/duckgres_server/enable_backfill_form.htmlindex 746e6d06187b..4207ebd43f1f 100644--- a/posthog/templates/admin/posthog/duckgres_server/enable_backfill_form.html+++ b/posthog/templates/admin/posthog/duckgres_server/enable_backfill_form.html@@ -3,9 +3,8 @@{% block content %}<p>Onboard another team onto this organization's existing managed warehouse. Runs the same flow as the-in-product onboarding API: creates the duckgres team row and records the team's-<code>DuckgresServerTeam</code> membership with its schema name as the backfill suffix. The-organization's feature flag is not required here.</p>+in-product onboarding API: creates the control-plane team row with its schema name and enables+backfill for that team. The organization's feature flag is not required here.</p><p>Organization: <code>{{ server.organization_id }}</code> — server <code>{{ server.host }}</code></p>diff --git a/posthog/templates/admin/posthog/duckgres_server/provision_form.html b/posthog/templates/admin/posthog/duckgres_server/provision_form.htmlindex bd0e901525f5..defe1103adc4 100644--- a/posthog/templates/admin/posthog/duckgres_server/provision_form.html+++ b/posthog/templates/admin/posthog/duckgres_server/provision_form.html@@ -4,8 +4,8 @@{% block content %}<p>Provision a new managed warehouse for an organization and its first team. This runs the sameflow as the in-product provision API: the duckgres control-plane <code>/provision</code> call, then-the <code>DuckgresServer</code> and <code>DuckgresServerTeam</code>-records for the team. The organization's <code>data-warehouse-scene</code> feature flag is+the local <code>DuckgresServer</code> connection record and the control-plane team row.+The organization's <code>data-warehouse-scene</code> feature flag is<strong>not</strong> required here.</p><p><strong>This makes a real control-plane call.</strong> In environments where<code>DUCKGRES_API_URL</code> is unset, it returns "not configured" and persists nothing.</p>diff --git a/products/data_warehouse/backend/presentation/views/data_warehouse.py b/products/data_warehouse/backend/presentation/views/data_warehouse.pyindex 2700000991bb..4be3954f5d0c 100644--- a/products/data_warehouse/backend/presentation/views/data_warehouse.py+++ b/products/data_warehouse/backend/presentation/views/data_warehouse.py@@ -888,8 +888,8 @@ class DataWarehouseViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):def onboard_team(self, request: Request, **kwargs) -> Response:"""Onboard this project onto the organization's existing managed warehouse.- Requires a schema name; records the project's membership both in duckgres and in the- Django backfill state. Restricted to organization admins.+ Requires a schema name and records the project's membership in the Duckgres control plane.+ Restricted to organization admins."""admin_error = self._require_organization_admin(request, "onboard this project for")if admin_error is not None:diff --git a/products/data_warehouse/backend/presentation/views/managed_warehouse.py b/products/data_warehouse/backend/presentation/views/managed_warehouse.pyindex 4a11b5225df7..3f1608f56c8a 100644--- a/products/data_warehouse/backend/presentation/views/managed_warehouse.py+++ b/products/data_warehouse/backend/presentation/views/managed_warehouse.py@@ -271,6 +271,7 @@ def provision(require_enabled=require_enabled,)if status.is_success(resp.status_code) and isinstance(resp.data, dict):+ _invalidate_team_state_cache(organization_id)_persist_duckgres_server(organization_id, database_name, resp.data)# Complete the row BEFORE registering the team: registration kicks off the# SQL-editor query-source setup and discovery against this row's warehouse.@@ -456,7 +457,10 @@ def create_team("schema_data_imports_name": schema_data_imports_name,}body.update({key: value for key, value in optional_fields.items() if value is not None})- return _request("POST", organization_id, "/teams", json_body=body, require_enabled=require_enabled)+ resp = _request("POST", organization_id, "/teams", json_body=body, require_enabled=require_enabled)+ if status.is_success(resp.status_code):+ _invalidate_team_state_cache(organization_id)+ return respdef update_team(@@ -471,9 +475,12 @@ def update_team(Presence-aware on the duckgres side: only the fields present in the body change, socallers pass exactly what they want written (e.g. just ``earliest_event_date``)."""- return _request(+ resp = _request("PUT", organization_id, f"/teams/{team_id}", json_body=dict(fields), require_enabled=require_enabled)+ if status.is_success(resp.status_code) or resp.status_code == status.HTTP_404_NOT_FOUND:+ _invalidate_team_state_cache(organization_id)+ return respdef push_team_earliest_event_date(organization_id: UUID | str, team_id: int, earliest: date | None) -> bool:@@ -528,7 +535,16 @@ def delete_team(organization_id: UUID | str, team_id: int, require_enabled: boolduckgres answers 409 for the org's last team (the org must be deprovisioned or deletedinstead)."""- return _request("DELETE", organization_id, f"/teams/{team_id}", require_enabled=require_enabled)+ resp = _request("DELETE", organization_id, f"/teams/{team_id}", require_enabled=require_enabled)+ if status.is_success(resp.status_code) or resp.status_code == status.HTTP_404_NOT_FOUND:+ _invalidate_team_state_cache(organization_id)+ return resp+++def _invalidate_team_state_cache(organization_id: UUID | str) -> None:+ from posthog.ducklake import cp_teams # noqa: PLC0415++ cp_teams.invalidate_org_cache(str(organization_id))def onboard_team(@@ -728,6 +744,7 @@ def block_team_deletion(team_id: int, organization_id: UUID | str) -> str | Nonedef deprovision(organization_id: UUID | str, require_enabled: bool = True) -> Response:resp = _request("POST", organization_id, "/deprovision", require_enabled=require_enabled)if status.is_success(resp.status_code):+ _invalidate_team_state_cache(organization_id)# Deprovision is not re-POSTable (Duckgres 409s once the org leaves a deprovisionable# state), so a failed local cleanup must converge via the retrying task, not the operator.try:diff --git a/products/data_warehouse/frontend/generated/api.ts b/products/data_warehouse/frontend/generated/api.tsindex 99a3a66f260b..9889ba1c4b16 100644--- a/products/data_warehouse/frontend/generated/api.ts+++ b/products/data_warehouse/frontend/generated/api.ts@@ -411,8 +411,8 @@ export const getDataWarehouseOnboardTeamCreateUrl = (projectId: string) => {/*** Onboard this project onto the organization's existing managed warehouse.*- * Requires a schema name; records the project's membership both in duckgres and in the- * Django backfill state. Restricted to organization admins.+ * Requires a schema name and records the project's membership in the Duckgres control plane.+ * Restricted to organization admins.*/export const dataWarehouseOnboardTeamCreate = async (projectId: string,diff --git a/products/data_warehouse/frontend/generated/api.zod.ts b/products/data_warehouse/frontend/generated/api.zod.tsindex 03aa89940d81..24144305a625 100644--- a/products/data_warehouse/frontend/generated/api.zod.ts+++ b/products/data_warehouse/frontend/generated/api.zod.ts@@ -12,8 +12,8 @@ import * as zod from 'zod'/*** Onboard this project onto the organization's existing managed warehouse.*- * Requires a schema name; records the project's membership both in duckgres and in the- * Django backfill state. Restricted to organization admins.+ * Requires a schema name and records the project's membership in the Duckgres control plane.+ * Restricted to organization admins.*/export const DataWarehouseOnboardTeamCreateBody = /* @__PURE__ */ zod.object({schema_name: zoddiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.pyindex 65f797e3f0af..893a3431e224 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/enablement.py@@ -37,7 +37,7 @@ def is_duckgres_sink_team_member(team_id: int) -> bool:control plane can't answer — the caller decides how to degrade."""organization_id = _get_org_id_for_team(team_id)- teams = cp_teams.list_org_teams(organization_id)+ teams = cp_teams.list_org_teams(organization_id, use_cache=False)if teams is None:raise RuntimeError(f"duckgres control plane unreachable resolving sink membership for team {team_id}")return any(team.team_id == team_id for team in teams)@@ -77,7 +77,7 @@ def duckgres_sink_enablement() -> SinkEnablement | None:from posthog.ducklake.models import DuckgresServerfrom posthog.models.team.team import Team- rows = cp_teams.list_member_teams()+ rows = cp_teams.list_member_teams(use_cache=False)if rows is None:raise CPUnavailableError("duckgres control plane unreachable; keeping the previous sink enablement")@@ -133,9 +133,3 @@ def duckgres_sink_enablement() -> SinkEnablement | None:logger.exception("duckgres_sink_flag_evaluation_failed", team_id=row.team_id)capture_exception(e)return SinkEnablement(team_ids=enabled, team_org_budgets=team_org_budgets)---def duckgres_sink_team_ids() -> list[int] | None:- """Back-compat view of duckgres_sink_enablement: just the enabled team ids."""- enablement = duckgres_sink_enablement()- return None if enablement is None else enablement.team_idsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.pyindex c9fad2a14267..f28641901285 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_enablement.py@@ -7,7 +7,6 @@ from posthog.models import Organization, Teamfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres import enablementfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres.enablement import (- duckgres_sink_team_ids,is_duckgres_sink_team_member,)@@ -47,7 +46,10 @@ def test_duckgres_sink_flag_evaluated_locally_with_group_properties(mock_feature_enabled.return_value = Truewith _patch_all_rows([_cp_row(team)]):- assert duckgres_sink_team_ids() == [team.id]+ result = enablement.duckgres_sink_enablement()++ assert result is not None+ assert result.team_ids == [team.id]mock_feature_enabled.assert_called_once_with("duckgres-batch-sink",@@ -76,7 +78,10 @@ def test_duckgres_sink_skips_team_when_flag_unresolved_locally(mock_feature_enabled.return_value = Nonewith _patch_all_rows([_cp_row(team)]):- assert duckgres_sink_team_ids() == []+ result = enablement.duckgres_sink_enablement()++ assert result is not None+ assert result.team_ids == []@pytest.mark.django_dbdiff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_processor.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_processor.pyindex 0bb2add93ea8..46cea393cb99 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_processor.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/duckgres/test_processor.py@@ -23,8 +23,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline@pytest.fixture(autouse=True)def _stub_schema_resolver():- # _duckgres_schema_name now resolves the team's table_suffix via the ORM;- # these are no-DB unit tests, so pin a deterministic schema name.+ # These no-DB unit tests pin the control-plane-backed schema resolver.with patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.duckgres.processor.duckgres_data_imports_schema",return_value="posthog_data_imports_team_1",