: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(data-warehouse): validate LinkedIn Ads account ID is numeric at setup (#68941)
Tom Owersf86be30c8988
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.pyindex 14333f362e54..db493aa9b4ec 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@@ -138,6 +138,15 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResuif not config.account_id or not config.linkedin_ads_integration_id:return False, "Account ID and LinkedIn Ads integration are required"+ # LinkedIn only accepts the numeric ad account ID. A free-text value (a profile URL, a+ # name, stray whitespace) is otherwise accepted here and only fails on the first sync, so+ # reject it up front with the same guidance the sync-time error gives.+ if not config.account_id.isdigit():+ return (+ False,+ "The LinkedIn Ads Account ID must be the numeric account ID from your LinkedIn Campaign Manager (digits only).",+ )+try:Integration.objects.get(id=config.linkedin_ads_integration_id, team_id=team_id)return True, Nonediff --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.pyindex d6f616d3e32b..3c99815d7072 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@@ -55,6 +55,25 @@ class TestLinkedInAdsSource:assert error_message is not Noneassert "Account ID and LinkedIn Ads integration are required" in error_message+ @pytest.mark.parametrize(+ "invalid_account_id",+ [+ "Reed Lnkedin",+ "https://www.linkedin.com/company/recruiteasy-ca",+ " 789",+ "789 ",+ "acc-789",+ ],+ )+ def test_validate_credentials_non_numeric_account_id(self, invalid_account_id):+ invalid_config = LinkedinAdsSourceConfig(linkedin_ads_integration_id=456, account_id=invalid_account_id)++ is_valid, error_message = self.source.validate_credentials(invalid_config, self.team_id)++ assert is_valid is False+ assert error_message is not None+ assert "numeric account ID" in error_message+@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.linkedin_ads.source.Integration")def test_validate_credentials_integration_not_found(self, mock_integration_model):"""Test credential validation when integration doesn't exist."""