: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
feat(data-warehouse): add PlanetScale source (#78830)
Tom Owers1e4689a3cd0e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.mdindex 818419868c0a..4074d1e15756 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md@@ -492,6 +492,7 @@ the row lists both.| pipedrive | HTTP + Webhook | requests + `WebhookSourceManager` | ✅ (pull) / ➖ (webhook) || pipeliner | HTTP | requests | ✅ || plain | HTTP | requests | ✅ |+| planetscale | DB protocol | pymysql (delegates to MySQLSource) | ➖ || planhat | HTTP | requests | ✅ || platform_sh | HTTP | requests | ✅ || plausible | HTTP | requests | ✅ |@@ -1215,7 +1216,6 @@ doesn't conflict with concurrent PRs.- pipeliner- pivotal_tracker- piwik-- planetscale- planning_center- plunk- pluralsight_flowdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/planetscale.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/planetscale.pyindex fffdc9cb4d2c..debd54ac6c74 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/planetscale.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs/planetscale.py@@ -6,4 +6,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common imp@config.configclass PlanetScaleSourceConfig(config.Config):- pass+ host: str+ database: str+ user: str+ password: str+ port: int = config.value(converter=int)+ schema: str | None = Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/planetscale.py b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/planetscale.pynew file mode 100644index 000000000000..91dd5d4c41db--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/planetscale.py@@ -0,0 +1,63 @@+from collections.abc import Iterator+from contextlib import contextmanager+from typing import Any++from django.conf import settings++import pymysql++from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mysql import MySQLSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.mysql.mysql import (+ _MYSQL_SAFE_CONVERSIONS,+ MySQLImplementation,+ _connect_with_transient_retry,+)++# Vitess' default OLTP workload caps a SELECT at 100,000 rows and aborts it after 20 seconds,+# which no full table extract survives. OLAP lifts both limits for reads.+_VITESS_OLAP_INIT_COMMAND = "SET workload = 'OLAP';"+++class PlanetScaleImplementation(MySQLImplementation):+ """MySQL driver specialized for PlanetScale's Vitess endpoints.++ Everything except the connection itself is plain MySQL, so only `connect` is overridden:+ PlanetScale terminates TLS on every connection and offers no SSH tunnel, and Vitess needs+ the OLAP workload hint before it will stream a whole table.+ """++ @contextmanager+ def connect(+ self,+ config: MySQLSourceConfig,+ *,+ read_timeout: int | None = None,+ ) -> Iterator[pymysql.Connection]:+ ssl_ca = "/etc/ssl/cert.pem" if settings.DEBUG else "/etc/ssl/certs/ca-certificates.crt"++ # PlanetScale has no SSH tunnel option, so this resolves to the configured host and+ # port. It is reused for the shared connection logging that wraps every SQL source.+ with self._ssh_tunnel_endpoint(config) as (host, port):+ kwargs: dict[str, Any] = {+ "host": host,+ # pymysql rejects a non-int port; config.port arrives as a string when the config+ # is built directly rather than through the int-coercing from_dict.+ "port": int(port),+ "database": config.database,+ "user": config.user,+ "password": config.password,+ "connect_timeout": 10,+ "ssl_ca": ssl_ca,+ # PlanetScale serves a publicly trusted certificate for the connect host, so both+ # chain and hostname verification can be required. Without `ssl_verify_identity`+ # pymysql accepts any valid certificate, which lets anyone able to redirect the+ # connection impersonate PlanetScale and capture these credentials.+ "ssl_verify_cert": True,+ "ssl_verify_identity": True,+ "conv": _MYSQL_SAFE_CONVERSIONS,+ "init_command": _VITESS_OLAP_INIT_COMMAND,+ }+ if read_timeout is not None:+ kwargs["read_timeout"] = read_timeout+ with _connect_with_transient_retry(kwargs) as conn:+ yield conndiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/source.pyindex 791bf0569357..df56db366448 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/source.py@@ -1,21 +1,107 @@-from typing import cast+import re+from typing import Optional, castfrom posthog.schema import (DataWarehouseSourceCategory,ExternalDataSourceType as SchemaExternalDataSourceType,+ ReleaseStatus,SourceConfig,+ SourceFieldInputConfig,+ SourceFieldInputConfigType,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, SimpleSource+from posthog.exceptions_capture import capture_exception++from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldTypefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.registry import SourceRegistry-from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.planetscale import (- PlanetScaleSourceConfig,+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mysql import MySQLSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.mysql.source import MySQLSource+from products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.planetscale import (+ PlanetScaleImplementation,)from products.warehouse_sources.backend.types import ExternalDataSourceType+_PLANETSCALE_IMPLEMENTATION = PlanetScaleImplementation()++# planetscale.com is the dashboard, never a database endpoint — branch connect hosts live on+# psdb.cloud. Pasting the dashboard address otherwise fails as an opaque connection timeout.+_PLANETSCALE_WEB_HOST_RE = re.compile(r"(^|\.)planetscale\.com$", re.IGNORECASE)++_CONNECT_HOST_EXAMPLE = "aws.connect.psdb.cloud"++_HOST_CAPTION = (+ "In the PlanetScale dashboard, open your database, pick the branch, and click **Connect**. "+ "Create a password there and copy the host, username, and password it shows. The host looks "+ f"like `{_CONNECT_HOST_EXAMPLE}`. PlanetScale always connects over TLS, which PostHog uses by "+ "default. A read-only password is enough for syncing."+)++_HOST_IS_URL_ERROR = (+ "Enter just the hostname in the host field, for example "+ f"{_CONNECT_HOST_EXAMPLE}. Remove any scheme, username, password, port, or path."+)++_HOST_IS_DASHBOARD_ERROR = (+ "That address is the PlanetScale dashboard, not a database host. Open your database in "+ "PlanetScale, click Connect, create a password, and use the host it shows, for example "+ f"{_CONNECT_HOST_EXAMPLE}."+)++_HOST_NOT_RESOLVED_ERROR = (+ "Could not resolve that host. Use the host shown under Connect in your PlanetScale database, "+ f"for example {_CONNECT_HOST_EXAMPLE}."+)++_GENERIC_CONNECTION_ERROR = "Could not connect to PlanetScale. Please check all connection details are valid."++# Create-time refinement of pymysql's catch-all connect error (2003), which collapses a bad host,+# a closed port, and a firewall drop into one message. Mirrors the MySQL source's handling with+# PlanetScale's own guidance. Kept out of `get_non_retryable_errors`, which the sync path also+# consults for retry classification.+_VALIDATE_CONNECTION_HINTS: list[tuple[str, str]] = [+ ("Name or service not known", _HOST_NOT_RESOLVED_ERROR),+ ("nodename nor servname provided", _HOST_NOT_RESOLVED_ERROR),+ (+ "Connection refused",+ "Could not connect on that host and port. PlanetScale accepts MySQL connections on port "+ "3306 at the host shown under Connect in your database.",+ ),+ (+ "timed out",+ "The connection timed out. Check that the branch is awake in PlanetScale and that the host "+ "and port are correct.",+ ),+ (+ "Unknown database",+ "That database does not exist on this PlanetScale branch. Check the database name is correct.",+ ),+]++_TLS_HANDSHAKE_ERROR = (+ "We couldn't open a TLS connection to PlanetScale. Check that the host is the branch connect "+ f"host, for example {_CONNECT_HOST_EXAMPLE}, and that the port is 3306."+)+++def _bare_host(host: str) -> str:+ """Reduce a pasted value to a bare host: drop any path and surrounding whitespace."""+ return (host or "").strip().split("/", 1)[0]+@SourceRegistry.register-class PlanetScaleSource(SimpleSource[PlanetScaleSourceConfig]):+class PlanetScaleSource(MySQLSource):+ """PlanetScale speaks the MySQL wire protocol, so it reuses the MySQL driver wholesale.++ Only the connection differs: TLS is mandatory, credentials are per-branch, and there is no+ SSH tunnel to configure.+ """++ api_docs_url = "https://planetscale.com/docs"++ @property+ def get_implementation(self) -> PlanetScaleImplementation:+ return _PLANETSCALE_IMPLEMENTATION+@propertydef source_type(self) -> ExternalDataSourceType:return ExternalDataSourceType.PLANETSCALE@@ -25,9 +111,107 @@ class PlanetScaleSource(SimpleSource[PlanetScaleSourceConfig]):return SourceConfig(name=SchemaExternalDataSourceType.PLANET_SCALE,category=DataWarehouseSourceCategory.DATABASES,- keywords=["sql", "mysql"],+ keywords=["sql", "mysql", "vitess"],label="PlanetScale",+ caption="Enter your PlanetScale branch credentials to pull your data into the PostHog Data warehouse.",iconPath="/static/services/planetscale.svg",- fields=cast(list[FieldType], []),- unreleasedSource=True,+ docsUrl="https://posthog.com/docs/cdp/sources/planetscale",+ fields=cast(+ list[FieldType],+ [+ SourceFieldInputConfig(+ name="host",+ label="Host",+ type=SourceFieldInputConfigType.TEXT,+ required=True,+ placeholder=_CONNECT_HOST_EXAMPLE,+ caption=_HOST_CAPTION,+ secret=False,+ ),+ SourceFieldInputConfig(+ name="port",+ label="Port",+ type=SourceFieldInputConfigType.NUMBER,+ required=True,+ placeholder="3306",+ secret=False,+ ),+ SourceFieldInputConfig(+ name="database",+ label="Database",+ type=SourceFieldInputConfigType.TEXT,+ required=True,+ placeholder="my-database",+ caption="The PlanetScale database name, shown in the connection details.",+ secret=False,+ ),+ SourceFieldInputConfig(+ name="user",+ label="Username",+ type=SourceFieldInputConfigType.TEXT,+ required=True,+ placeholder="",+ secret=False,+ ),+ SourceFieldInputConfig(+ name="password",+ label="Password",+ type=SourceFieldInputConfigType.PASSWORD,+ required=True,+ placeholder="",+ secret=True,+ ),+ SourceFieldInputConfig(+ name="schema",+ label="Schema",+ type=SourceFieldInputConfigType.TEXT,+ required=False,+ placeholder="Leave blank to include every database on the branch",+ secret=False,+ ),+ ],+ ),+ releaseStatus=ReleaseStatus.ALPHA,)++ def get_non_retryable_errors(self) -> dict[str, str | None]:+ errors = super().get_non_retryable_errors()+ # The inherited message tells the user to turn SSL off, which PlanetScale doesn't allow.+ errors["[SSL: WRONG_VERSION_NUMBER]"] = _TLS_HANDSHAKE_ERROR+ return errors++ def validate_credentials(+ self,+ config: MySQLSourceConfig,+ team_id: int,+ schema_name: Optional[str] = None,+ api_version: str | None = None,+ ) -> tuple[bool, str | None]:+ host = config.host or ""+ if "://" in host:+ return False, _HOST_IS_URL_ERROR++ if _PLANETSCALE_WEB_HOST_RE.search(_bare_host(host)):+ return False, _HOST_IS_DASHBOARD_ERROR++ valid_host, host_errors = self.is_database_host_valid(host, team_id, using_ssh_tunnel=False)+ if not valid_host:+ return valid_host, host_errors++ try:+ self.get_schemas(config, team_id, api_version=api_version)+ except Exception as e:+ # Failures we already classify as non-retryable during sync are expected user or+ # upstream errors, not bugs on our side, so they're reported without capturing.+ error_msg = " ".join(str(arg) for arg in e.args) if e.args else str(e)+ for hint_pattern, hint_message in _VALIDATE_CONNECTION_HINTS:+ if hint_pattern in error_msg:+ return False, hint_message+ for pattern, friendly_error in self.get_non_retryable_errors().items():+ if pattern in error_msg:+ return False, friendly_error or _GENERIC_CONNECTION_ERROR++ capture_exception(e)+ return False, _GENERIC_CONNECTION_ERROR++ return True, Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale.py b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale.pynew file mode 100644index 000000000000..6e95235544e6--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale.py@@ -0,0 +1,83 @@+from contextlib import contextmanager+from typing import Any, cast++import pytest+from unittest import mock++from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mysql import MySQLSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.planetscale import (+ PlanetScaleSourceConfig,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.planetscale import (+ PlanetScaleImplementation,+)++_CONNECT_TARGET = (+ "products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.planetscale."+ "_connect_with_transient_retry"+)+++def _config(port: int | str = 3306) -> MySQLSourceConfig:+ # The runtime config for this source is the generated `PlanetScaleSourceConfig`; the driver+ # signatures are typed against the MySQL one it structurally matches. It deliberately has no+ # `using_ssl` or `ssh_tunnel` field, which is what these tests exercise.+ return cast(+ MySQLSourceConfig,+ PlanetScaleSourceConfig(+ host="aws.connect.psdb.cloud",+ database="my-database",+ user="user",+ password="password",+ port=cast(int, port),+ schema=None,+ ),+ )+++@contextmanager+def _connect(config: MySQLSourceConfig, **kwargs: Any):+ connection = mock.MagicMock()+ with mock.patch(_CONNECT_TARGET) as connect:+ connect.return_value.__enter__.return_value = connection+ with PlanetScaleImplementation().connect(config, **kwargs) as opened:+ assert opened is connection+ yield connect.call_args.args[0]+++def test_connection_always_uses_tls_and_the_olap_workload():+ with _connect(_config()) as kwargs:+ # PlanetScale mandates TLS, and Vitess' default OLTP workload caps reads at 100k rows.+ assert kwargs["ssl_ca"]+ assert kwargs["init_command"] == "SET workload = 'OLAP';"+++def test_connection_verifies_the_server_certificate_and_hostname():+ with _connect(_config()) as kwargs:+ # Without these, pymysql accepts any valid certificate for any host, so anyone able to+ # redirect the connection could impersonate PlanetScale and capture the credentials.+ assert kwargs["ssl_verify_cert"] is True+ assert kwargs["ssl_verify_identity"] is True+++def test_connection_details_come_from_the_config():+ with _connect(_config()) as kwargs:+ assert kwargs["host"] == "aws.connect.psdb.cloud"+ assert kwargs["database"] == "my-database"+ assert kwargs["user"] == "user"+ assert kwargs["password"] == "password"++[email protected]("port", [3306, "3306"])+def test_port_is_coerced_to_int(port):+ # pymysql rejects a string port, and a config built outside `from_dict` skips the converter.+ with _connect(_config(port)) as kwargs:+ assert kwargs["port"] == 3306+++def test_read_timeout_is_only_sent_when_requested():+ with _connect(_config()) as kwargs:+ assert "read_timeout" not in kwargs++ with _connect(_config(), read_timeout=600) as kwargs:+ assert kwargs["read_timeout"] == 600diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale_source.pynew file mode 100644index 000000000000..1c26ef874ba1--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale/test_planetscale_source.py@@ -0,0 +1,208 @@+import dataclasses+from typing import cast++import pytest+from unittest import mock++from posthog.schema import DataWarehouseSourceCategory, ReleaseStatus, SourceFieldInputConfig++from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mysql import MySQLSourceConfig+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.planetscale import (+ PlanetScaleSourceConfig,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.planetscale import (+ PlanetScaleImplementation,+)+from products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.source import PlanetScaleSource+from products.warehouse_sources.backend.types import ExternalDataSourceType+++def _config(host: str = "aws.connect.psdb.cloud") -> MySQLSourceConfig:+ # The runtime config for this source is the generated `PlanetScaleSourceConfig`; the driver+ # signatures are typed against the MySQL one it structurally matches.+ return cast(+ MySQLSourceConfig,+ PlanetScaleSourceConfig(+ host=host,+ database="my-database",+ user="user",+ password="password",+ port=3306,+ schema=None,+ ),+ )+++def _field(name: str) -> SourceFieldInputConfig:+ return next(+ field+ for field in PlanetScaleSource().get_source_config.fields+ if isinstance(field, SourceFieldInputConfig) and field.name == name+ )+++def test_source_type_and_implementation():+ source = PlanetScaleSource()++ assert source.source_type == ExternalDataSourceType.PLANETSCALE+ # The MySQL driver reads `config.using_ssl`, which this source's config has no field for.+ assert isinstance(source.get_implementation, PlanetScaleImplementation)+++def test_source_is_visible_and_alpha():+ config = PlanetScaleSource().get_source_config++ assert not config.unreleasedSource+ assert config.featureFlag is None+ assert config.releaseStatus == ReleaseStatus.ALPHA+ assert config.category == DataWarehouseSourceCategory.DATABASES++[email protected]("name", ["ssh_tunnel", "using_ssl"])+def test_mysql_only_fields_are_not_offered(name):+ # PlanetScale mandates TLS and has no SSH tunnel story, so neither field applies.+ assert all(field.name != name for field in PlanetScaleSource().get_source_config.fields)+++def test_generated_config_matches_the_offered_fields():+ # The generated config is what the pipeline actually receives, so a field added to the form+ # without regenerating would surface as a missing attribute mid-sync.+ form_fields = {field.name for field in PlanetScaleSource().get_source_config.fields}+ config_fields = {field.name for field in dataclasses.fields(PlanetScaleSourceConfig)}++ assert form_fields == config_fields+++def test_schema_field_is_optional_for_multi_schema_discovery():+ assert _field("schema").required is False+++def test_password_field_is_secret():+ password = _field("password")++ assert password.secret is True+ assert password.required is True+++def test_host_field_guides_to_the_branch_connect_host():+ host = _field("host")++ assert host.placeholder == "aws.connect.psdb.cloud"+ assert host.caption is not None+ assert "psdb.cloud" in host.caption+++def test_tls_error_replaces_the_mysql_advice_to_disable_ssl():+ errors = PlanetScaleSource().get_non_retryable_errors()+ message = errors["[SSL: WRONG_VERSION_NUMBER]"]++ assert message is not None+ assert "Use SSL" not in message+ # Inherited MySQL classifications still apply — PlanetScale speaks the same protocol.+ assert "Access denied for user" in errors+++ "host",+ ["mysql://aws.connect.psdb.cloud", "https://aws.connect.psdb.cloud"],+)+def test_url_in_host_field_is_rejected_before_connecting(host):+ with mock.patch.object(PlanetScaleSource, "get_schemas") as get_schemas:+ success, error = PlanetScaleSource().validate_credentials(_config(host), team_id=1)++ get_schemas.assert_not_called()+ assert success is False+ assert error is not None+ assert "hostname" in error++[email protected]("host", ["app.planetscale.com", "PLANETSCALE.COM", " planetscale.com "])+def test_dashboard_host_is_rejected_with_connect_guidance(host):+ with mock.patch.object(PlanetScaleSource, "get_schemas") as get_schemas:+ success, error = PlanetScaleSource().validate_credentials(_config(host), team_id=1)++ get_schemas.assert_not_called()+ assert success is False+ assert error is not None+ assert "aws.connect.psdb.cloud" in error+++def test_psdb_host_is_not_treated_as_the_dashboard():+ with (+ mock.patch.object(PlanetScaleSource, "is_database_host_valid", return_value=(True, None)),+ mock.patch.object(PlanetScaleSource, "get_schemas", return_value=[]) as get_schemas,+ ):+ success, error = PlanetScaleSource().validate_credentials(_config(), team_id=1)++ get_schemas.assert_called_once()+ assert success is True+ assert error is None+++def test_unsafe_host_is_rejected_before_connecting():+ with (+ mock.patch.object(PlanetScaleSource, "is_database_host_valid", return_value=(False, "host not allowed")),+ mock.patch.object(PlanetScaleSource, "get_schemas") as get_schemas,+ ):+ success, error = PlanetScaleSource().validate_credentials(_config("127.0.0.1"), team_id=1)++ get_schemas.assert_not_called()+ assert success is False+ assert error == "host not allowed"+++def test_validate_credentials_never_opens_an_ssh_tunnel():+ # `MySQLSource.validate_credentials` reads `config.ssh_tunnel`, which this config has no+ # field for, so the override must not fall through to it.+ with (+ mock.patch.object(PlanetScaleSource, "is_database_host_valid", return_value=(True, None)),+ mock.patch.object(PlanetScaleSource, "get_schemas", return_value=[]),+ mock.patch.object(PlanetScaleSource, "ssh_tunnel_is_valid") as ssh_tunnel_is_valid,+ ):+ success, _ = PlanetScaleSource().validate_credentials(_config(), team_id=1)++ ssh_tunnel_is_valid.assert_not_called()+ assert success is True+++ "raw_error,expected_fragment",+ [+ ("Name or service not known", "Could not resolve that host"),+ ("nodename nor servname provided", "Could not resolve that host"),+ ("Connection refused", "port 3306"),+ ("Can't connect to MySQL server on 'x' (timed out)", "timed out"),+ ("(1049, \"Unknown database 'x'\")", "does not exist on this PlanetScale branch"),+ ("(1045, \"Access denied for user 'x'\")", "Invalid user or password"),+ ("branch is missing or sleeping: abc", "deleted or put to sleep"),+ ],+)+def test_connection_failures_map_to_actionable_messages(raw_error, expected_fragment):+ with (+ mock.patch.object(PlanetScaleSource, "is_database_host_valid", return_value=(True, None)),+ mock.patch.object(PlanetScaleSource, "get_schemas", side_effect=Exception(raw_error)),+ mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.source.capture_exception"+ ) as capture,+ ):+ success, error = PlanetScaleSource().validate_credentials(_config(), team_id=1)++ assert success is False+ assert error is not None+ assert expected_fragment in error+ capture.assert_not_called()+++def test_unrecognized_failure_is_captured_and_reported_generically():+ with (+ mock.patch.object(PlanetScaleSource, "is_database_host_valid", return_value=(True, None)),+ mock.patch.object(PlanetScaleSource, "get_schemas", side_effect=Exception("something unexpected")),+ mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.planetscale.source.capture_exception"+ ) as capture,+ ):+ success, error = PlanetScaleSource().validate_credentials(_config(), team_id=1)++ capture.assert_called_once()+ assert success is False+ assert error == "Could not connect to PlanetScale. Please check all connection details are valid."