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(hubspot): retry token refresh on transient rate limit (#64180)

Tom Owerse85065155ae0
diff --git a/posthog/temporal/data_imports/sources/hubspot/test/test_hubspot_auth.py b/posthog/temporal/data_imports/sources/hubspot/test/test_hubspot_auth.py
index c14a8bdd2ae6..a4ede04fbf27 100644
--- a/posthog/temporal/data_imports/sources/hubspot/test/test_hubspot_auth.py
+++ b/posthog/temporal/data_imports/sources/hubspot/test/test_hubspot_auth.py
@@ -112,3 +112,17 @@ def test_transient_status_reraises_after_exhausting_retries() -> None:
with pytest.raises(HubspotRetryableError, match="You have reached your rate limit."):
hubspot_refresh_access_token("refresh-token")
assert session.post.call_count == 5
+
+
+def test_non_transient_status_is_not_retried() -> None:
+ # A non-transient status (e.g. invalid_grant) must surface immediately, not be retried.
+ session = MagicMock()
+ session.post.return_value = _make_response(400, {"message": "missing or invalid refresh token"})
+ with patch(
+ "posthog.temporal.data_imports.sources.hubspot.auth.make_tracked_session",
+ return_value=session,
+ ):
+ with pytest.raises(Exception) as exc_info:
+ hubspot_refresh_access_token("refresh-token")
+ assert not isinstance(exc_info.value, HubspotRetryableError)
+ assert session.post.call_count == 1