Skip to content

: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.

fix(custom): stop retrying an upstream payment-required rejection (#115032)

Tom Owers63ecdcd67494
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
index 83a791deaa7a..3690a75ba01d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/source.py
@@ -961,6 +961,9 @@ class CustomSource(SimpleSource[CustomSourceConfig]):
# manifest-driven, so the 404 recurs on every retry — stop and point at the config.
# The message omits the URL, which carries the customer's hostname.
"404 Client Error": "The upstream API returned HTTP 404 Not Found. Check that the base URL and the resource's path in the manifest are correct and that the endpoint exists, then try again.",
+ # The upstream account's plan doesn't cover this endpoint. The plan only changes on the
+ # customer's side, so every retry gets the same refusal.
+ "402 Client Error": "Your API provider requires a paid plan for this data. Upgrade or reactivate your plan with them, or turn off syncing for this table, then re-enable the sync.",
# A network proxy rejected the request before it reached the upstream API. On PostHog
# Cloud this is the egress proxy refusing a URL it isn't allowed to reach (a private or
# internal address); it can also be an upstream proxy in front of the customer's API
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
index aef4fafe79df..1e7bbd2fc6c2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/custom/test_custom_source.py
@@ -1849,15 +1849,25 @@ class TestCustomSourceNonRetryableErrors(SimpleTestCase):
non_retryable = CustomSource().get_non_retryable_errors()
assert any(key in str(ctx.exception) for key in non_retryable)
- def test_http_407_proxy_auth_is_classified_non_retryable(self):
- # A proxy that refuses the request (the egress proxy blocking a disallowed address, or an
- # upstream proxy needing credentials) returns 407 deterministically, so retrying can't fix
- # it. Build the real requests HTTPError raise_for_status() produces, so this breaks if the
- # matched substring drifts. Route through the classifier's message so a regression that
- # leaves it None (raw driver text) is caught too. The URL is a placeholder.
+ @parameterized.expand(
+ [
+ # A proxy that refuses the request (the egress proxy blocking a disallowed address, or
+ # an upstream proxy needing credentials).
+ ("proxy_auth", 407, "Proxy Authentication Required", "proxy"),
+ # An upstream account whose plan doesn't cover the endpoint.
+ ("payment_required", 402, "Payment Required", "paid plan"),
+ ]
+ )
+ def test_deterministic_http_rejection_is_classified_non_retryable(
+ self, _name: str, status_code: int, reason: str, expected_phrase: str
+ ) -> None:
+ # Both statuses recur on every retry until the customer changes something. Build the real
+ # requests HTTPError raise_for_status() produces, so this breaks if the matched substring
+ # drifts. Route through the classifier's message so a regression that leaves it None (raw
+ # driver text) is caught too. The URL is a placeholder.
response = Response()
- response.status_code = 407
- response.reason = "Proxy Authentication Required"
+ response.status_code = status_code
+ response.reason = reason
response.url = "https://api.example.com/data"
with self.assertRaises(requests.exceptions.HTTPError) as ctx:
response.raise_for_status()
@@ -1866,7 +1876,7 @@ class TestCustomSourceNonRetryableErrors(SimpleTestCase):
matches = [friendly for key, friendly in non_retryable.items() if key in str(ctx.exception)]
assert matches
assert matches[0] is not None
- assert "proxy" in matches[0].lower()
+ assert expected_phrase in matches[0].lower()
def test_non_json_response_message_is_classified_non_retryable(self):
# The REST client raises RESTClientNonRetryableError when a configured endpoint