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(pinterest_ads): raise timeout for analytics fan-out requests (#107351)

Tom Owers7088c71f380a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/pinterest_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/pinterest_ads.py
index 86bcaea633c9..07aa57623006 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/pinterest_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/pinterest_ads.py
@@ -12,6 +12,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.pinterest_
ANALYTICS_ENDPOINT_PATHS,
ANALYTICS_ID_PARAM_NAMES,
ANALYTICS_MAX_IDS,
+ ANALYTICS_REQUEST_TIMEOUT_SECONDS,
BASE_URL,
ENTITY_ENDPOINT_PATHS,
PAGE_SIZE,
@@ -331,7 +332,7 @@ def _iter_fanned_out_analytics(
**extra_params,
}
- data = _make_request(session, url, params)
+ data = _make_request(session, url, params, timeout=(30, ANALYTICS_REQUEST_TIMEOUT_SECONDS))
rows = parse_rows(data)
if rows is None:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/settings.py
index 81ffc46db620..ec780cbc6204 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/settings.py
@@ -13,6 +13,11 @@ PAGE_SIZE = 250
ANALYTICS_MAX_IDS = 250
ANALYTICS_MAX_DATE_RANGE_DAYS = 90
DEFAULT_LOOKBACK_DAYS = 89
+# A fanned-out analytics request asks for a full batch of ids, every metric column, a full date
+# chunk and (for targeting analytics) several breakdown dimensions at once, so its response
+# legitimately takes longer to read than the default 30s used for lightweight entity/list
+# requests. Only the read timeout is widened — the connect timeout stays at 30s.
+ANALYTICS_REQUEST_TIMEOUT_SECONDS = 60
# Pinterest Ads API v5 analytics columns
# Full column reference: https://developers.pinterest.com/docs/api/v5/ads-analytics/
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py
index 09fc1f162a66..979dbfc93950 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py
@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.pinterest_
ANALYTICS_ENDPOINT_PATHS,
ANALYTICS_ENTITY_SOURCES,
ANALYTICS_ID_PARAM_NAMES,
+ ANALYTICS_REQUEST_TIMEOUT_SECONDS,
ENTITY_ENDPOINT_PATHS,
PINTEREST_ADS_CONFIG,
TARGETING_ANALYTICS_ENDPOINT_PATHS,
@@ -523,6 +524,10 @@ class TestIterAnalyticsRowsFresh:
assert yielded[0][0]["currency"] == "USD"
# Single (batch, chunk) run → no next cursor → no save
manager.save_state.assert_not_called()
+ # A fanned-out request bundles a full id batch, every metric column and a full date chunk,
+ # so its response needs more than the default 30s given to lightweight entity/list
+ # requests. Only the read timeout is widened; the connect timeout stays at 30s.
+ assert mock_request.call_args.kwargs["timeout"] == (30, ANALYTICS_REQUEST_TIMEOUT_SECONDS)
@mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.pinterest_ads.pinterest_ads.fetch_account_currency"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/utils.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/utils.py
index b2ae038c2f42..1f341bebb83c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/utils.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/utils.py
@@ -98,8 +98,13 @@ def _chunk_date_range(start_date: str, end_date: str) -> list[tuple[str, str]]:
wait=wait_exponential_jitter(initial=1, max=60),
reraise=True,
)
-def _make_request(session: requests.Session, url: str, params: Optional[dict] = None) -> Any:
- response = session.get(url, params=params, timeout=30)
+def _make_request(
+ session: requests.Session,
+ url: str,
+ params: Optional[dict] = None,
+ timeout: int | tuple[int, int] = 30,
+) -> Any:
+ response = session.get(url, params=params, timeout=timeout)
response.raise_for_status()
return response.json()