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(data-warehouse): mark HubSpot missing refresh token as non-retryable (#61627)

Tom Owersd0aaeb8f6be8
diff --git a/posthog/temporal/data_imports/sources/hubspot/source.py b/posthog/temporal/data_imports/sources/hubspot/source.py
index f8ec68ecf8bc..91cf24c4ee2d 100644
--- a/posthog/temporal/data_imports/sources/hubspot/source.py
+++ b/posthog/temporal/data_imports/sources/hubspot/source.py
@@ -85,6 +85,11 @@ class HubspotSource(ResumableSource[HubspotSourceConfig | HubspotSourceOldConfig
return {
"missing or invalid refresh token": "Your HubSpot connection is invalid or expired. Please reconnect it.",
"missing or unknown hub id": None,
+ # Raised by source_for_pipeline when the source config carries no refresh token at all
+ # (integration never connected or lost its token). Retrying cannot recover.
+ "Hubspot refresh token not found": "Your HubSpot connection is missing its refresh token. Please reconnect it.",
+ # Raised by source_for_pipeline (OAuth path) when the integration is missing its access or refresh token.
+ "Hubspot refresh or access token not found": "Your HubSpot connection is missing its refresh token. Please reconnect it.",
}
# TODO: clean up hubspot job inputs to not have two auth config options
diff --git a/posthog/temporal/data_imports/sources/hubspot/test/test_source_routing.py b/posthog/temporal/data_imports/sources/hubspot/test/test_source_routing.py
index 390cf3b41448..dc8a734bd647 100644
--- a/posthog/temporal/data_imports/sources/hubspot/test/test_source_routing.py
+++ b/posthog/temporal/data_imports/sources/hubspot/test/test_source_routing.py
@@ -217,3 +217,21 @@ class TestSettingsShape:
field = config.incremental_fields[0]
assert field["field"] == config.cursor_filter_property_field
assert field["type"] == IncrementalFieldType.DateTime
+
+
+ "error_msg",
+ [
+ # HubspotSourceOldConfig path
+ "Hubspot refresh token not found for job 019cdc50-67a5-0000-c023-0d6a4e057e9b",
+ # HubspotSourceConfig OAuth path
+ "Hubspot refresh or access token not found for job 019cdc50-67a5-0000-c023-0d6a4e057e9b",
+ ],
+)
+def test_missing_token_error_is_non_retryable(error_msg: str) -> None:
+ """Each ValueError raised when a token is missing must match a non-retryable pattern,
+ otherwise the job retries a permanent misconfiguration forever."""
+ patterns = HubspotSource().get_non_retryable_errors()
+ assert any(pattern in error_msg for pattern in patterns), (
+ f"HubSpot error {error_msg!r} did not match any non-retryable pattern"
+ )