: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(wordpress): surface actionable errors for connection failures (#72173)
Tom Owers3a51158b5c1c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.pyindex ee73730ec88c..4eb9bbe5831c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/tests/test_wordpress.py@@ -4,6 +4,8 @@ from typing import Any, Optionalimport pytestfrom unittest import mock+import requests+from products.warehouse_sources.backend.temporal.data_imports.sources.wordpress import wordpress as wordpress_modulefrom products.warehouse_sources.backend.temporal.data_imports.sources.wordpress.settings import WORDPRESS_ENDPOINTSfrom products.warehouse_sources.backend.temporal.data_imports.sources.wordpress.wordpress import (@@ -279,13 +281,22 @@ class TestValidateCredentials:assert valid is Falseassert msg == "Invalid WordPress site URL"- def test_request_exception_returns_failure(self):- import requests-- with self._patch_session(raises=requests.exceptions.ConnectionError("boom")):+ @pytest.mark.parametrize(+ "exc_factory, expected_msg_substr",+ [+ (lambda: requests.exceptions.SSLError("certificate verify failed"), "secure connection"),+ (lambda: requests.exceptions.ConnectionError("boom"), "Couldn't connect"),+ (lambda: requests.exceptions.Timeout("slow"), "took too long"),+ (lambda: requests.exceptions.RequestException("weird"), "Couldn't reach"),+ ],+ )+ def test_request_exception_returns_actionable_message(self, exc_factory, expected_msg_substr):+ # The raw exception string (e.g. an SSL traceback) must never surface to the user.+ with self._patch_session(raises=exc_factory()):valid, msg = validate_credentials("https://example.com", None, None)assert valid is False- assert "boom" in (msg or "")+ assert expected_msg_substr in (msg or "")+ assert "certificate verify failed" not in (msg or "")def test_rejects_redirect_response(self):with self._patch_session(_response(status_code=302)) as patched:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.pyindex ab441f852b03..6bb4c81629e6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/wordpress/wordpress.py@@ -247,8 +247,20 @@ def validate_credentials(timeout=10,allow_redirects=False,)- except requests.exceptions.RequestException as e:- return False, str(e)+ except requests.exceptions.SSLError:+ return False, (+ "Couldn't establish a secure connection to the WordPress site — its TLS certificate failed "+ "verification. Install a publicly trusted certificate (not a self-signed one) on the site and try again."+ )+ except requests.exceptions.ConnectionError:+ return False, "Couldn't connect to the WordPress site. Check the site URL is correct and the site is reachable."+ except requests.exceptions.Timeout:+ return False, "The WordPress site took too long to respond. Check that it's reachable and try again."+ except requests.exceptions.RequestException:+ return (+ False,+ "Couldn't reach the WordPress site. Check the site URL and that the site is online, then try again.",+ )if response.is_redirect or response.is_permanent_redirect:return False, HOST_NOT_ALLOWED_ERROR