: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(warehouse-sources): explain why a woocommerce store connection failed (#113385)
Tom Owers05f15186b6f3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/source.pyindex 5761d2d39fa3..cdef159a47b3 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/source.py@@ -165,7 +165,21 @@ class WooCommerceSource("and have Read permission for this store.")- return False, "Could not connect to your WooCommerce store. Please check the store URL."+ if status is None:+ return False, (+ "Couldn't reach your WooCommerce store. Check that the store URL is your public site address "+ "and try again."+ )++ # The host answered but `/wp-json/wc/v3` didn't exist: usually a URL that isn't the WordPress+ # site root, or a site on Plain permalinks, which serves the REST API under `?rest_route=` only.+ if status == 404:+ return False, (+ "Your store answered, but its WooCommerce REST API wasn't found. Check the store URL and that "+ "WordPress permalinks aren't set to Plain, then try again."+ )++ return False, "Your WooCommerce store returned an error. Check that the store is online and try again."def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[WooCommerceResumeConfig]:return ResumableSourceManager[WooCommerceResumeConfig](inputs, WooCommerceResumeConfig)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/tests/test_woocommerce_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/tests/test_woocommerce_source.pyindex 3d0f066cd51a..59353d9b0fa9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/tests/test_woocommerce_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/woocommerce/tests/test_woocommerce_source.py@@ -53,26 +53,31 @@ class TestWooCommerceSource:)@pytest.mark.parametrize(- "status, schema_name, expected_valid",+ "status, schema_name, expected_valid, expected_message_fragment",[- (200, None, True),- (200, "orders", True),- (401, None, False),- (403, None, True), # valid key without scope for the probe endpoint -> allowed at create- (403, "orders", False), # but rejected for a specific schema check- (404, None, False),- (None, None, False), # connection error+ (200, None, True, None),+ (200, "orders", True, None),+ (401, None, False, "consumer key and secret"),+ (403, None, True, None), # valid key without scope for the probe endpoint -> allowed at create+ (403, "orders", False, "blocked before it reached WooCommerce"), # but rejected for a specific schema+ (404, None, False, "permalinks"),+ (500, None, False, "returned an error"),+ (None, None, False, "Couldn't reach your WooCommerce store"), # connection error],)@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.woocommerce.source.validate_woocommerce_credentials")- def test_validate_credentials(self, mock_validate, status, schema_name, expected_valid):+ def test_validate_credentials(self, mock_validate, status, schema_name, expected_valid, expected_message_fragment):mock_validate.return_value = status- is_valid, _ = self.source.validate_credentials(self.config, self.team_id, schema_name=schema_name)+ is_valid, message = self.source.validate_credentials(self.config, self.team_id, schema_name=schema_name)assert is_valid is expected_valid+ if expected_message_fragment is None:+ assert message is None+ else:+ assert message is not None and expected_message_fragment in messagemock_validate.assert_called_once_with("https://example.com", "ck_test", "cs_test", self.team_id)def test_validate_credentials_missing_fields(self):