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(managed-warehouse): gate ducklake registration on a provisioned duckgres server (#76982)

Eric Duongfefed33a8fe3
diff --git a/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py b/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
index d110c5ab787f..a9a103b684ce 100644
--- a/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
+++ b/products/managed_warehouse/backend/temporal/ducklake_register_data_imports_workflow.py
@@ -132,7 +132,7 @@ async def ducklake_register_data_imports_gate_activity(inputs: DuckLakeRegisterD
return False
try:
- return feature_enabled_or_false(
+ flag_enabled = feature_enabled_or_false(
DUCKLAKE_DATA_IMPORTS_REGISTRATION_WORKFLOW_FLAG,
str(team.uuid),
groups={
@@ -151,6 +151,26 @@ async def ducklake_register_data_imports_gate_activity(inputs: DuckLakeRegisterD
capture_exception(error)
return False
+ if not flag_enabled:
+ return False
+
+ # The flag alone is not sufficient: registration resolves the team's schema through
+ # the duckgres control plane, which only knows orgs with a provisioned server, so a
+ # flag-enabled team in an unprovisioned org would fail the prepare activity with a
+ # spurious "control plane unreachable" error. Dev mode has no DuckgresServer rows
+ # (connections come from env vars), so the check applies only to real deployments.
+ if is_dev_mode():
+ return True
+
+ server = await database_sync_to_async(get_duckgres_server_by_team_org)(inputs.team_id)
+ if server is None:
+ await logger.ainfo(
+ "No DuckgresServer provisioned for team's organization; skipping DuckLake data imports registration"
+ )
+ return False
+
+ return True
+
@activity.defn
async def prepare_ducklake_data_imports_registration_activity(
@@ -525,7 +545,7 @@ class DuckLakeRegisterDataImportsWorkflow(PostHogWorkflow):
retry_policy=RetryPolicy(maximum_attempts=1),
)
if not should_register:
- logger.info("DuckLake data imports registration workflow disabled by feature flag")
+ logger.info("DuckLake data imports registration gated off (flag disabled or no DuckgresServer)")
return
schema_id = str(inputs.schema_id)
diff --git a/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py b/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
index ada5c74ae099..9be17ac437b4 100644
--- a/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
+++ b/products/managed_warehouse/backend/tests/temporal/test_ducklake_register_data_imports_workflow.py
@@ -71,6 +71,23 @@ async def test_registration_gate_uses_independent_feature_flag(monkeypatch, atea
assert captured["send_feature_flag_events"] is False
[email protected]("server_provisioned", [True, False])
+async def test_registration_gate_requires_provisioned_duckgres_server(monkeypatch, ateam, server_provisioned):
+ monkeypatch.setattr(registration_module, "feature_enabled_or_false", lambda *args, **kwargs: True)
+ monkeypatch.setattr(registration_module, "is_dev_mode", lambda: False)
+ monkeypatch.setattr(
+ registration_module,
+ "get_duckgres_server_by_team_org",
+ lambda team_id: MagicMock() if server_provisioned else None,
+ )
+
+ result = await ducklake_register_data_imports_gate_activity(DuckLakeRegisterDataImportsGateInputs(team_id=ateam.id))
+
+ assert result is server_provisioned
+
+
@pytest.mark.asyncio
@pytest.mark.django_db
async def test_prepare_registration_pins_the_import_jobs_prepared_generation(ateam):