: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(data-warehouse): explain an unsupported character in pasted credentials (#119264)
Tom Owersf75bcce621ce
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_source/helpers.py b/products/warehouse_sources/backend/presentation/views/external_data_source/helpers.pyindex e37b4037d84b..93681481743c 100644--- a/products/warehouse_sources/backend/presentation/views/external_data_source/helpers.py+++ b/products/warehouse_sources/backend/presentation/views/external_data_source/helpers.py@@ -50,6 +50,11 @@ INVALID_CREDENTIALS_FALLBACK_MESSAGE = ("We couldn't validate those credentials. Check they're correct and have the required access, then try again.")+UNSUPPORTED_CREDENTIAL_CHARACTER_MESSAGE = (+ "One of the values you entered contains an unsupported character, such as a curly quote. "+ "Copy the value again from your provider and paste only the value."+)+UNVERIFIED_CONNECTION_WARNING = ("Source saved, but the API could not reach the database. Syncs and live queries connect ""from other services and can still work. Details: {error}"@@ -156,6 +161,10 @@ def _credentials_validation_failed(source: AnySource, team_id: int, error: Exceperror, so capture it for us and hand back an actionable message — the same treatment schemadiscovery already gives an unexpected error just below the credential check."""capture_exception(error, {"source_type": str(source.source_type), "team_id": team_id})+ # http.client encodes header values as latin-1, so a key pasted with a curly quote or similar+ # character fails mid-request in any source that doesn't check the value up front.+ if isinstance(error, UnicodeEncodeError):+ return False, UNSUPPORTED_CREDENTIAL_CHARACTER_MESSAGEreturn False, INVALID_CREDENTIALS_FALLBACK_MESSAGEdiff --git a/products/warehouse_sources/backend/tests/api/test_external_data_source.py b/products/warehouse_sources/backend/tests/api/test_external_data_source.pyindex dbe055d4bb45..a4ce99e4352f 100644--- a/products/warehouse_sources/backend/tests/api/test_external_data_source.py+++ b/products/warehouse_sources/backend/tests/api/test_external_data_source.py@@ -65,6 +65,7 @@ from products.warehouse_sources.backend.presentation.views.external_data_schemafrom products.warehouse_sources.backend.presentation.views.external_data_source.helpers import (DIRECT_QUERY_UNSUPPORTED_SOURCE_MESSAGE,INVALID_CREDENTIALS_FALLBACK_MESSAGE,+ UNSUPPORTED_CREDENTIAL_CHARACTER_MESSAGE,_classify_refresh_schemas_error,get_credential_account_field_names,get_declared_field_names,@@ -512,13 +513,23 @@ class TestExternalDataSource(APIBaseTest):assert "at least one destination" in response.json()["detail"]assert not ExternalDataSource.objects.filter(team_id=self.team.pk).exists()+ @parameterized.expand(+ [+ ("unexpected_error", AttributeError("boom"), INVALID_CREDENTIALS_FALLBACK_MESSAGE),+ (+ "non_latin1_header_value",+ UnicodeEncodeError("latin-1", "sk_test\u2019", 7, 8, "ordinal not in range(256)"),+ UNSUPPORTED_CREDENTIAL_CHARACTER_MESSAGE,+ ),+ ]+ )@patch("products.warehouse_sources.backend.temporal.data_imports.sources.stripe.source.StripeSource.validate_credentials",- side_effect=AttributeError("boom"),)- def test_create_surfaces_400_when_credential_probe_raises(self, _mock_validate):+ def test_create_surfaces_400_when_credential_probe_raises(self, _name, error, expected_message, mock_validate):# A source whose validate_credentials raises (rather than returning (False, message)) must# not 500 the create request — the user gets an actionable message and no source is created.+ mock_validate.side_effect = errorresponse = self.client.post(f"/api/environments/{self.team.pk}/external_data_sources/",data={@@ -534,7 +545,7 @@ class TestExternalDataSource(APIBaseTest):)self.assertEqual(response.status_code, 400)- self.assertEqual(response.json()["message"], INVALID_CREDENTIALS_FALLBACK_MESSAGE)+ self.assertEqual(response.json()["message"], expected_message)self.assertFalse(ExternalDataSource.objects.filter(team_id=self.team.pk).exists())def test_api_version_pin_is_read_only_via_api(self):