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(supabase): guide users who paste the project URL as the host (#67293)

Tom Owers22c5228326a6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py
index 0f01ccf809b7..ec8e439daf67 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/source.py
@@ -33,6 +33,18 @@ _SourceField = (
# connection failures. Users need the connection pooler host instead.
_SUPABASE_DIRECT_HOST_RE = re.compile(r"^db\.[a-z0-9]+\.supabase\.co$", re.IGNORECASE)
+# The Supabase dashboard shows `https://<ref>.supabase.co` as the "Project URL" — that's the
+# REST/API endpoint, not a Postgres host. Pasting it (often with the scheme) into the host field
+# just yields an opaque DNS failure, so detect it and point users at the actual database host.
+_SUPABASE_PROJECT_HOST_RE = re.compile(r"^(?P<ref>[a-z0-9]+)\.supabase\.co$", re.IGNORECASE)
+
+
+def _strip_host_scheme(host: str) -> str:
+ """Reduce a pasted value to a bare host: drop any URL scheme, path, and surrounding whitespace."""
+ stripped = re.sub(r"^[a-z][a-z0-9+.-]*://", "", (host or "").strip(), flags=re.IGNORECASE)
+ return stripped.split("/", 1)[0]
+
+
_SUPABASE_POOLER_HOST_CAPTION = (
"To get your connection string, click **Connect** in the top bar of your Supabase "
"dashboard, open the **Direct** tab, and pick **Session pooler** or **Direct "
@@ -90,6 +102,19 @@ class SupabaseSource(PostgresSource):
def validate_credentials(
self, config: PostgresSourceConfig, team_id: int, schema_name: Optional[str] = None
) -> tuple[bool, str | None]:
+ bare_host = _strip_host_scheme(config.host or "")
+ project_host = _SUPABASE_PROJECT_HOST_RE.match(bare_host)
+ if project_host:
+ # Project refs are lowercase, and the pooler username (postgres.<ref>) is
+ # case-sensitive — canonicalize so the suggested values are copy-pasteable.
+ ref = project_host.group("ref").lower()
+ return False, (
+ f"'{bare_host}' looks like your Supabase project URL, not a database "
+ "host. For standard syncs use the Session pooler host (aws-0-<region>.pooler.supabase.com) with "
+ f"username postgres.{ref}; for change data capture use the direct host db.{ref}.supabase.co and "
+ "enable Supabase's IPv4 add-on."
+ )
+
# The direct host (IPv6-only by default) is the only host that supports logical
# replication, so CDC users need it. We let the real connection attempt decide
# reachability — it succeeds when the IPv4 add-on is enabled — and only swap in a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py
index b320890576dc..2aa945c2fd3e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/supabase/test_supabase_source.py
@@ -60,6 +60,34 @@ def test_direct_host_failure_surfaces_ipv4_addon_hint(host):
assert "ipv4 add-on" in error.lower()
+ "host",
+ [
+ "abcdefgh.supabase.co",
+ "https://abcdefgh.supabase.co",
+ "https://abcdefgh.supabase.co/",
+ " HTTPS://ABCDEFGH.SUPABASE.CO ",
+ ],
+)
+def test_project_url_host_is_rejected_before_connecting(host):
+ # The dashboard's "Project URL" (`<ref>.supabase.co`) is the REST endpoint, not a database
+ # host. Pasting it (often with the scheme) must short-circuit to actionable guidance instead
+ # of attempting a doomed connection that yields an opaque DNS error.
+ config = mock.MagicMock(host=host)
+
+ with mock.patch.object(PostgresSource, "validate_credentials") as super_validate:
+ success, error = SupabaseSource().validate_credentials(config, team_id=1)
+
+ super_validate.assert_not_called()
+ assert success is False
+ assert error is not None
+ assert "project url" in error.lower()
+ assert "pooler.supabase.com" in error
+ # The suggested pooler username is case-sensitive, so the ref must be lowercased even when
+ # the user typed the host in caps (see the uppercase parametrized case).
+ assert "postgres.abcdefgh" in error
+
+
@pytest.mark.parametrize(
"host",
[