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(warehouse-sources): tell users to reconnect when a source's account is gone (#97519)

Tom Owersaeb278a0d992
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
index 9b5c8a31efd0..f685e2f3fc71 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
@@ -122,6 +122,11 @@ LOGGER = get_logger(__name__)
MAX_RESUMABLE_SOURCE_RETRIES = 3 if settings.DEBUG else 15
MAX_INCREMENTAL_SOURCE_RETRIES = 3 if settings.DEBUG else 9
+MISSING_INTEGRATION_MESSAGE = (
+ "The connected account for this source is no longer available — it may have been disconnected. "
+ "Please reconnect the source's account."
+)
+
Any_Source_Errors: dict[str, str | None] = {
"Could not establish session to SSH gateway": None,
# Raised by `_check_direct_host` when a direct (untunneled) database connection's host doesn't
@@ -154,7 +159,13 @@ Any_Source_Errors: dict[str, str | None] = {
"rows to update. Choose a unique primary key in the table's sync settings, or switch it to full "
"table replication, then re-enable the sync."
),
- "Integration matching query does not exist": "The connected account for this source is no longer available — it may have been disconnected. Please reconnect the source's account.",
+ "Integration matching query does not exist": MISSING_INTEGRATION_MESSAGE,
+ # `OAuthMixin.get_oauth_integration` catches `Integration.DoesNotExist` and re-raises these
+ # two, so the ORM wording above never reaches here for the sources that go through it. Left
+ # unclassified they were retried to exhaustion and then shown raw, echoing an internal
+ # integration id back at the customer.
+ "Integration not found:": MISSING_INTEGRATION_MESSAGE,
+ "Missing integration ID": MISSING_INTEGRATION_MESSAGE,
# A fatal TLS alert from the remote host (raised in the shared HTTP transport for every
# REST-based source). The server refused the handshake, which is deterministic for a given
# host/TLS config — retrying replays the identical failure, so it's not transient. Usually a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
index 4b3192abcc14..c0cc3913a243 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test_mixins.py
@@ -13,7 +13,10 @@ from parameterized import parameterized
from posthog.models.integration import Integration
from posthog.temporal.common.errors import NonReportableError
-from products.warehouse_sources.backend.temporal.data_imports.external_data_job import Any_Source_Errors
+from products.warehouse_sources.backend.temporal.data_imports.external_data_job import (
+ MISSING_INTEGRATION_MESSAGE,
+ Any_Source_Errors,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matches
from products.warehouse_sources.backend.temporal.data_imports.sources.common.mixins import (
HostNotAllowedError,
@@ -555,6 +558,37 @@ class TestOAuthMixinIntegrationFetchResilience(SimpleTestCase):
assert get.call_count == 2
+ @parameterized.expand(
+ [
+ ("deleted_integration", Integration.DoesNotExist(), 4212),
+ ("unset_integration_id", None, 0),
+ ]
+ )
+ def test_lookup_failure_is_classified_for_every_oauth_source(
+ self, _name: str, side_effect: Exception | None, integration_id: int
+ ):
+ # Every OAuth source shares this lookup, so its two failure messages have to be in the
+ # all-source map: unclassified they get retried to exhaustion and then shown to the
+ # customer raw, with the integration id in them.
+ get = mock.Mock(side_effect=side_effect)
+
+ with (
+ patch(f"{_MIXINS_MODULE}.Integration.objects.get", get),
+ patch(f"{_MIXINS_MODULE}.close_old_connections"),
+ patch(f"{_MIXINS_MODULE}.time.sleep"),
+ ):
+ with pytest.raises(ValueError) as raised:
+ OAuthMixin().get_oauth_integration(integration_id=integration_id, team_id=2)
+
+ assert error_message_matches(str(raised.value), Any_Source_Errors.keys())
+ friendly = next(
+ message
+ for pattern, message in Any_Source_Errors.items()
+ if error_message_matches(str(raised.value), [pattern])
+ )
+ assert friendly == MISSING_INTEGRATION_MESSAGE
+ assert str(integration_id) not in MISSING_INTEGRATION_MESSAGE
+
class TestDirectHostIsCheckedAtConnect(SimpleTestCase):
# A direct database connection is a raw socket that the HTTP egress proxy never sees, and the