: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(neon): point a missing database at the neon connect dialog (#114987)
Tom Owers653d82952d57
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/neon/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/neon/source.pyindex 73b61dda8166..1e5190d46f28 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/neon/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/neon/source.py@@ -1,3 +1,5 @@+from typing import Optional+from products.warehouse_sources.backend.facade.source_config import (DataWarehouseSourceCategory,ReleaseStatus,@@ -9,7 +11,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 (+ _DATABASE_NOT_FOUND_VALIDATION_ERROR,+ PostgresSource,+)from products.warehouse_sources.backend.types import ExternalDataSourceType_NEON_POOLED_HOST_CDC_ERROR = (@@ -19,6 +24,12 @@ _NEON_POOLED_HOST_CDC_ERROR = ("enabled in your Neon project settings.")+# Each Neon branch has its own databases, and the default one is neondb, not postgres.+_NEON_DATABASE_NOT_FOUND_ERROR = (+ "That database doesn't exist on this Neon branch. Copy the database name from the Connect dialog "+ "in your Neon Console, then try again."+)+def _is_neon_pooled_host(host: str) -> bool:bare = (host or "").strip().lower()@@ -104,3 +115,18 @@ class NeonSource(PostgresSource):require_ssl=require_ssl,team_id=team_id,)++ def validate_credentials(+ self,+ config: PostgresSourceConfig,+ team_id: int,+ schema_name: Optional[str] = None,+ api_version: str | None = None,+ require_ssl: bool = False,+ ) -> tuple[bool, str | None]:+ success, error = super().validate_credentials(+ config, team_id, schema_name=schema_name, api_version=api_version, require_ssl=require_ssl+ )+ if not success and error == _DATABASE_NOT_FOUND_VALIDATION_ERROR:+ return False, _NEON_DATABASE_NOT_FOUND_ERROR+ return success, errordiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/neon/test_neon_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/neon/test_neon_source.pyindex b14eab498bdc..ab4f1b33a1f6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/neon/test_neon_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/neon/test_neon_source.py@@ -1,8 +1,15 @@import pytestfrom unittest import mock-from products.warehouse_sources.backend.temporal.data_imports.sources.neon.source import NeonSource-from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import PostgresSource+from products.warehouse_sources.backend.temporal.data_imports.sources.neon.source import (+ _NEON_DATABASE_NOT_FOUND_ERROR,+ NeonSource,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.postgres.source import (+ _DATABASE_NOT_FOUND_VALIDATION_ERROR,+ _INVALID_CREDENTIALS_VALIDATION_ERROR,+ PostgresSource,+)@pytest.mark.parametrize(@@ -42,3 +49,18 @@ def test_cdc_prerequisites_delegate_for_direct_hosts(host):super_check.assert_called_once()assert super_check.call_args.kwargs["team_id"] == 7assert errors == []+++ "postgres_result,expected",+ [+ ((False, _DATABASE_NOT_FOUND_VALIDATION_ERROR), (False, _NEON_DATABASE_NOT_FOUND_ERROR)),+ ((False, _INVALID_CREDENTIALS_VALIDATION_ERROR), (False, _INVALID_CREDENTIALS_VALIDATION_ERROR)),+ ((True, None), (True, None)),+ ],+)+def test_validate_credentials_points_a_missing_database_at_the_neon_connect_dialog(postgres_result, expected):+ config = mock.MagicMock(host="ep-cool-darkness-123456.us-east-2.aws.neon.tech")++ with mock.patch.object(PostgresSource, "validate_credentials", return_value=postgres_result):+ assert NeonSource().validate_credentials(config, team_id=1) == expecteddiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex f322fe0b8a7f..6f5b0ab11626 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -172,6 +172,11 @@ _HOST_UNREACHABLE_VALIDATION_ERROR = (_CONNECT_TIMEOUT_VALIDATION_ERROR = "Connection timed out. Check that your database is reachable from the public internet and that PostHog's egress IP addresses are allowed through your firewall (see the docs). For a database that can't be exposed publicly, use the SSH tunnel option."+_DATABASE_NOT_FOUND_VALIDATION_ERROR = (+ "The database named in your connection details doesn't exist on this server. Check the database name is "+ "correct and try again."+)+PostgresErrors = {"password authentication failed for user": _INVALID_CREDENTIALS_VALIDATION_ERROR,# A proxy/pooler in front of some providers rejects bad credentials during its own@@ -293,7 +298,7 @@ PostgresErrors = {"Network is unreachable": _HOST_UNREACHABLE_ERROR,"No route to host": _HOST_UNREACHABLE_ERROR,"Is the server running on that host and accepting TCP/IP connections": _HOST_UNREACHABLE_VALIDATION_ERROR,- 'database "': "The database named in your connection details doesn't exist on this server. Check the database name is correct and try again.",+ 'database "': _DATABASE_NOT_FOUND_VALIDATION_ERROR,"timeout expired": _CONNECT_TIMEOUT_VALIDATION_ERROR,"the database system is starting up": "Your database is starting up or recovering. Wait a moment and try again.","SSL/TLS connection is required": "SSL/TLS connection is required but your database does not support it. Please enable SSL/TLS on your PostgreSQL server.",