: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(ducklake): make get_instance_region a lazy import in common helpers (#64913)
Ross264155eba89a
diff --git a/posthog/ducklake/common.py b/posthog/ducklake/common.pyindex 626dbf68f376..4b4f96efecb0 100644--- a/posthog/ducklake/common.py+++ b/posthog/ducklake/common.py@@ -25,8 +25,6 @@ import duckdbimport psycopgfrom psycopg import sql-from posthog.utils import get_instance_region-if TYPE_CHECKING:from posthog.ducklake.models import DuckgresServer, DuckLakeCatalog@@ -285,6 +283,10 @@ def _duckling_env_suffix() -> str:enabled yet, so that path is a no-op (raises rather than fabricating a bucket name);everything that isn't prod-US — hosted dev/staging, local dev — maps to "dev"."""+ # Lazy import so this module can be loaded standalone (see bin/check_ducklake_up)+ # without the full posthog package on sys.path.+ from posthog.utils import get_instance_region # noqa: PLC0415+region = (get_instance_region() or "").upper()if region == "EU":raise NotImplementedError("Managed warehouse is not enabled in the EU region")diff --git a/posthog/ducklake/test_common.py b/posthog/ducklake/test_common.pyindex 62c5fa87cb20..703206328b00 100644--- a/posthog/ducklake/test_common.py+++ b/posthog/ducklake/test_common.py@@ -25,11 +25,11 @@ class TestDeriveDucklingBucket:)def test_derives_bucket_from_region(self, _name: str, region: str | None, expected_bucket: str):# Mirrors the duckgres Crossplane composition: posthog-duckling-{org}-{suffix}.- with patch("posthog.ducklake.common.get_instance_region", return_value=region):+ with patch("posthog.utils.get_instance_region", return_value=region):assert derive_duckling_bucket("org-abc") == (expected_bucket, "us-east-1")def test_eu_is_not_enabled(self):- with patch("posthog.ducklake.common.get_instance_region", return_value="EU"):+ with patch("posthog.utils.get_instance_region", return_value="EU"):with pytest.raises(NotImplementedError, match="EU"):derive_duckling_bucket("org-1")