: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(bing_ads): treat non-numeric account ID as non-retryable (#63694)
Tom Owersb9c59d2a663c
diff --git a/posthog/temporal/data_imports/sources/bing_ads/bing_ads.py b/posthog/temporal/data_imports/sources/bing_ads/bing_ads.pyindex 17bfcbe57a6f..38368cc1a249 100644--- a/posthog/temporal/data_imports/sources/bing_ads/bing_ads.py+++ b/posthog/temporal/data_imports/sources/bing_ads/bing_ads.py@@ -89,6 +89,17 @@ def bing_ads_source(resource = BingAdsResource(resource_name)today = dt.date.today()+ # Bing Ads Account IDs are numeric. Users sometimes enter their alphanumeric Account+ # Number (e.g. "F118FDGN") instead, which can't be parsed into the integer the API+ # expects. Raise a deterministic, actionable error here so it can be flagged+ # non-retryable rather than crashing on a bare int() and retrying forever.+ if not account_id.isdigit():+ raise ValueError(+ "Bing Ads Account ID must be numeric. "+ f"The configured Account ID {account_id!r} is not a number — you may have entered "+ "your alphanumeric Account Number instead. Update the Account ID in the source "+ "settings and try again."+ )account_id_int = int(account_id)if schema.is_stats:diff --git a/posthog/temporal/data_imports/sources/bing_ads/source.py b/posthog/temporal/data_imports/sources/bing_ads/source.pyindex 60ad33b461bf..feec7db38962 100644--- a/posthog/temporal/data_imports/sources/bing_ads/source.py+++ b/posthog/temporal/data_imports/sources/bing_ads/source.py@@ -94,6 +94,14 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O# the id is volatile, so match only the stable prefix. Retrying can't recreate the row —# the customer has to reconnect."Integration not found": "The linked Bing Ads integration no longer exists. Please reconnect your Bing Ads integration.",+ # Non-numeric Account ID — the user entered their alphanumeric Account Number instead+ # of the numeric Account ID. Retrying can't fix a bad config value, so flag it and surface+ # actionable guidance. The matched phrase is stable and precedes the volatile id in the+ # raised message (see bing_ads_source.get_rows), keeping false positives at zero.+ "Bing Ads Account ID must be numeric": (+ "Bing Ads Account ID must be numeric. You may have entered your alphanumeric Account Number "+ "instead. Update the Account ID in the source settings and try again."+ ),# Deterministic credential/config errors raised in source_for_pipeline."Bing Ads access token not found": "Bing Ads OAuth access token is missing. Please reconnect your Bing Ads integration.","Bing Ads refresh token not found": "Bing Ads OAuth refresh token is missing. Please reconnect your Bing Ads integration.",diff --git a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads.py b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads.pyindex d28c3c53c221..454fde21ad38 100644--- a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads.py+++ b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads.py@@ -342,6 +342,32 @@ class TestBingAdsSource:assert isinstance(items, Iterable)list(items)+ @parameterized.expand(+ [+ ("account_number", "F118FDGN"),+ ("alphanumeric", "ABC123"),+ ("empty", ""),+ ]+ )+ @patch("posthog.temporal.data_imports.sources.bing_ads.bing_ads.BingAdsClient")+ @patch("posthog.temporal.data_imports.sources.bing_ads.bing_ads.integrations")+ def test_bing_ads_source_non_numeric_account_id(self, _name, account_id, mock_integrations, mock_client_class):+ """A non-numeric account ID raises a deterministic, non-retryable error instead of a bare int() crash."""+ mock_integrations.BING_ADS_DEVELOPER_TOKEN = "test_dev_token"++ result = bing_ads_source(+ account_id=account_id,+ resource_name="campaigns",+ access_token=self.access_token,+ refresh_token=self.refresh_token,+ resumable_source_manager=_mock_resumable_manager(),+ )++ with pytest.raises(ValueError, match="Bing Ads Account ID must be numeric"):+ items = result.items()+ assert isinstance(items, Iterable)+ list(items)+@patch("posthog.temporal.data_imports.sources.bing_ads.bing_ads.BingAdsClient")@patch("posthog.temporal.data_imports.sources.bing_ads.bing_ads.integrations")def test_bing_ads_source_incremental_missing_field(self, mock_integrations, mock_client_class):diff --git a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.pyindex 997e25e05f5d..560312d63990 100644--- a/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py+++ b/posthog/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py@@ -276,6 +276,14 @@ class TestBingAdsSource:# Integration deleted/disconnected — OAuthMixin.get_oauth_integration raises# `ValueError("Integration not found: <id>")`; match only the volatile-id-free prefix.("Integration not found", "Integration not found: 160672"),+ # Non-numeric Account ID — raised by bing_ads_source.get_rows. The matched phrase+ # precedes the volatile account id in the message.+ (+ "Bing Ads Account ID must be numeric",+ "Bing Ads Account ID must be numeric. The configured Account ID 'F118FDGN' is not a number — "+ "you may have entered your alphanumeric Account Number instead. Update the Account ID in the "+ "source settings and try again.",+ ),# Deterministic credential/config errors raised in source_for_pipeline.("Bing Ads access token not found", "Bing Ads access token not found for job abc"),("Bing Ads refresh token not found", "Bing Ads refresh token not found for job abc"),