: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(hubspot): stop reporting transient HubSpot API errors as exceptions (#73484)
Tom Owers8e4fb2f7f7a4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.pyindex c2142505e7c2..a5358b946916 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/source.py@@ -133,6 +133,22 @@ class HubspotSource(ResumableSource[HubspotSourceConfig | HubspotSourceOldConfig"Integration not found": "The linked HubSpot integration no longer exists. Please reconnect your HubSpot account.",}+ def get_retryable_errors(self) -> set[str]:+ # `hubspot.py`/`helpers.py` already retry these in-process via tenacity (5 attempts,+ # exponential backoff) before re-raising `HubspotRetryableError`. A 429/5xx/malformed-body+ # that survives all 5 attempts is a transient HubSpot/edge blip (e.g. Cloudflare 522), not+ # a bug — Temporal's activity retry recovers once the upstream issue clears, so keep it out+ # of error tracking as noise. Match the stable message prefix HubSpot's own status/url are+ # appended to, not the volatile status code or URL.+ return {+ "Hubspot API error (retryable): status=",+ "Hubspot API malformed JSON response (retryable)",+ "Hubspot search error (retryable): status=",+ "Hubspot search malformed JSON response (retryable)",+ "Hubspot v4 associations error (retryable): status=",+ "Hubspot v4 associations malformed JSON response (retryable)",+ }+# TODO: clean up hubspot job inputs to not have two auth config optionsdef parse_config(self, job_inputs: dict) -> HubspotSourceConfig | HubspotSourceOldConfig:if "hubspot_integration_id" in job_inputs.keys():diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.pyindex bfbb2fce1e09..785b9a6e9caf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/hubspot/test/test_source_routing.py@@ -256,6 +256,28 @@ def test_missing_token_error_is_non_retryable(error_msg: str) -> None:)+ "error_msg",+ [+ # fetch_page/_get, exhausted after tenacity's 5 in-process attempts (e.g. a Cloudflare 522)+ "Hubspot API error (retryable): status=522, url=https://api.hubapi.com/crm/v3/properties/meetings",+ "Hubspot API error (retryable): status=429, url=https://api.hubapi.com/crm/v3/objects/contacts",+ "Hubspot API malformed JSON response (retryable): url=https://api.hubapi.com/crm/v3/objects/deals",+ "Hubspot search error (retryable): status=503, url=https://api.hubapi.com/crm/v3/objects/contacts/search",+ "Hubspot search malformed JSON response (retryable): url=https://api.hubapi.com/crm/v3/objects/deals/search",+ "Hubspot v4 associations error (retryable): status=500, "+ "url=https://api.hubapi.com/crm/v4/associations/contacts/deals/batch/read",+ "Hubspot v4 associations malformed JSON response (retryable): "+ "url=https://api.hubapi.com/crm/v4/associations/contacts/deals/batch/read",+ ],+)+def test_transient_http_error_is_retryable(error_msg: str) -> None:+ patterns = HubspotSource().get_retryable_errors()+ assert any(pattern in error_msg for pattern in patterns), (+ f"HubSpot error {error_msg!r} did not match any retryable pattern"+ )++class TestApiVersion:def test_defaults_to_v3_until_date_version_is_verified(self) -> None:src = HubspotSource()