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(linkedin-ads): keep internals out of the credential validation error (#107379)

Tom Owers93b03f7fa01d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
index e1b926e5d2c8..04886da894a9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
@@ -47,6 +47,16 @@ from .linkedin_ads import (
linkedin_ads_source,
)
+_MISSING_INTEGRATION_ERROR = (
+ "The LinkedIn Ads connection for this source no longer exists. Reconnect your LinkedIn Ads account, then try again."
+)
+# The catch-all this backs also covers a transient database failure, which a reconnect never fixes,
+# so lead with the retry and keep reconnecting as the fallback.
+_CONNECTION_CHECK_ERROR = (
+ "PostHog couldn't check your LinkedIn Ads connection. Try again in a few minutes, "
+ "and reconnect your LinkedIn Ads account if it keeps failing."
+)
+
# LinkedIn's Marketing API uses monthly date-based versioning (YYYYMM) sent as a request header.
LINKEDIN_ADS_VERSION_202606 = "202606"
LINKEDIN_ADS_VERSION_202607 = "202607"
@@ -260,10 +270,10 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
Integration.objects.get(id=config.linkedin_ads_integration_id, team_id=team_id)
return True, None
except Integration.DoesNotExist:
- return False, "LinkedIn Ads integration not found. Please re-authenticate."
+ return False, _MISSING_INTEGRATION_ERROR
except Exception as e:
capture_exception(e)
- return False, f"Failed to validate LinkedIn Ads credentials: {str(e)}"
+ return False, _CONNECTION_CHECK_ERROR
def get_schemas(
self,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
index 726af7a7141e..315a9b6430d0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
@@ -10,6 +10,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_
)
from products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.client import LinkedinAdsClient
from products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.source import (
+ _CONNECTION_CHECK_ERROR,
+ _MISSING_INTEGRATION_ERROR,
LINKEDIN_ADS_VERSION_202606,
LINKEDIN_ADS_VERSION_202607,
LINKEDIN_ADS_VERSION_202608,
@@ -205,8 +207,7 @@ class TestLinkedInAdsSource:
is_valid, error_message = self.source.validate_credentials(self.config, self.team_id)
assert is_valid is False
- assert error_message is not None
- assert "LinkedIn Ads integration not found" in error_message
+ assert error_message == _MISSING_INTEGRATION_ERROR
@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.source.Integration")
@mock.patch(
@@ -223,9 +224,9 @@ class TestLinkedInAdsSource:
is_valid, error_message = self.source.validate_credentials(self.config, self.team_id)
assert is_valid is False
- assert error_message is not None
- assert "Failed to validate LinkedIn Ads credentials" in error_message
- assert "Database error" in error_message
+ # The raw exception text is a database internal the user can do nothing with; it belongs in
+ # error tracking, not in the wizard.
+ assert error_message == _CONNECTION_CHECK_ERROR
mock_capture_exception.assert_called_once()
@pytest.mark.parametrize(