: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(supabase): stop masking a clear connection error with the IPv4 hint (#80210)
Tom Owers165ef6dae216
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.pyindex 00e273cb4dff..75ed6c27e107 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@@ -19,7 +19,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.regfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.postgres import (PostgresSourceConfig,)-from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import PostgresSource+from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import (+ _HOST_UNREACHABLE_ERROR,+ PostgresSource,+)from products.warehouse_sources.backend.types import ExternalDataSourceType_SourceField = (@@ -126,10 +129,12 @@ class SupabaseSource(PostgresSource):# 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- # clearer message when it fails, since the generic Postgres error is opaque.+ # reachability — it succeeds when the IPv4 add-on is enabled. Only the unreachable+ # failure is the IPv4 case, so swap in Supabase-specific pooler guidance there; other+ # failures (bad password, missing database, SSL) already have clear messages, and+ # blaming them on IPv4 would misdirect the user.is_direct_host = bool(_SUPABASE_DIRECT_HOST_RE.match((config.host or "").strip()))success, error = super().validate_credentials(config, team_id, schema_name=schema_name)- if not success and is_direct_host:+ if not success and is_direct_host and error == _HOST_UNREACHABLE_ERROR:return False, _SUPABASE_DIRECT_HOST_IPV4_HINTreturn success, errordiff --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.pyindex 2aa945c2fd3e..76e6fe299948 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@@ -3,7 +3,10 @@ from unittest import mockfrom posthog.schema import ReleaseStatus, SourceFieldInputConfig-from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import PostgresSource+from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import (+ _HOST_UNREACHABLE_ERROR,+ PostgresSource,+)from products.warehouse_sources.backend.temporal.data_imports.sources.supabase.source import SupabaseSource@@ -47,12 +50,12 @@ def test_supabase_host_field_points_at_the_pooler():" db.abcdefgh.supabase.co ",],)-def test_direct_host_failure_surfaces_ipv4_addon_hint(host):+def test_direct_host_unreachable_surfaces_ipv4_addon_hint(host):# The direct host is the only one that supports logical replication (CDC), so we let the- # connection attempt run; on failure we explain the IPv4 add-on requirement.+ # connection attempt run; an unreachable host is the IPv6 case, so explain the IPv4 add-on.config = mock.MagicMock(host=host)- with mock.patch.object(PostgresSource, "validate_credentials", return_value=(False, "could not connect")):+ with mock.patch.object(PostgresSource, "validate_credentials", return_value=(False, _HOST_UNREACHABLE_ERROR)):success, error = SupabaseSource().validate_credentials(config, team_id=1)assert success is False@@ -60,6 +63,25 @@ def test_direct_host_failure_surfaces_ipv4_addon_hint(host):assert "ipv4 add-on" in error.lower()+ "postgres_error",+ [+ "Invalid user or password",+ "Database does not exist",+ ],+)+def test_direct_host_non_reachability_error_is_not_masked(postgres_error):+ # A clear failure like a bad password must reach the user unchanged — overwriting it with the+ # IPv4 hint would tell someone whose add-on is already enabled to fix a non-existent problem.+ config = mock.MagicMock(host="db.abcdefghijklmnop.supabase.co")++ with mock.patch.object(PostgresSource, "validate_credentials", return_value=(False, postgres_error)):+ success, error = SupabaseSource().validate_credentials(config, team_id=1)++ assert success is False+ assert error == postgres_error++@pytest.mark.parametrize("host",[