: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(warehouse-sources): name a Persona api that is not enabled (#127912)
jake sciotto34831d35004b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_error_contract.py b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_error_contract.pyindex 5c0111fac42b..709f9d41fafe 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_error_contract.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/test_source_error_contract.py@@ -479,6 +479,10 @@ def test_allowlists_name_only_extracting_sources(allowlist: dict[str, Any]) -> N# `requests.raise_for_status()` renders a blank one instead of "Unauthorized"/"Forbidden".("ZohoCRM", "401 Client Error: for url: https://www.zohoapis.com/crm/v8/Leads?page=1"),("ZohoCRM", "403 Client Error: for url: https://www.zohoapis.com/crm/v8/Notes?page=1"),+ (+ "Persona",+ "Persona API not enabled for this account: Workflows API is not enabled, url=https://api.withpersona.com/api/v1/workflow-runs",+ ),],)def test_narrowed_keys_still_match_permanent_errors(name: str, message: str) -> None:diff --git a/products/warehouse_sources/sources/persona/persona.py b/products/warehouse_sources/sources/persona/persona.pyindex dbdfcae4d45c..413a9831bcba 100644--- a/products/warehouse_sources/sources/persona/persona.py+++ b/products/warehouse_sources/sources/persona/persona.py@@ -47,6 +47,24 @@ class PersonaRedirectError(Exception):"""The API answered with a 3xx. Redirects are refused so the API key stays on the API host."""+class PersonaApiNotEnabledError(requests.HTTPError):+ pass+++def _api_not_enabled_detail(response: requests.Response) -> str | None:+ try:+ body = response.json()+ except ValueError:+ return None+ if not isinstance(body, dict):+ return None+ for error in body.get("errors") or []:+ detail = error.get("details") if isinstance(error, dict) else None+ if isinstance(detail, str) and detail.lower().endswith("api is not enabled"):+ return detail+ return None++def _refuse_redirect(response: requests.Response) -> None:if not 300 <= response.status_code < 400:return@@ -180,6 +198,11 @@ def _fetch_page(if not response.ok:logger.error(f"Persona API error: status={response.status_code}, body={response.text}, url={page_url}")+ detail = _api_not_enabled_detail(response) if response.status_code == 403 else None+ if detail:+ raise PersonaApiNotEnabledError(+ f"Persona API not enabled for this account: {detail}, url={page_url}", response=response+ )response.raise_for_status()return response.json()diff --git a/products/warehouse_sources/sources/persona/source.py b/products/warehouse_sources/sources/persona/source.pyindex 106ef1c201bf..456933543ff1 100644--- a/products/warehouse_sources/sources/persona/source.py+++ b/products/warehouse_sources/sources/persona/source.py@@ -98,6 +98,7 @@ Sandbox and production environments use separate API keys — use the one for th# Retrying can't fix a credential problem, so fail the sync. Match the stable status text# and base host, not the per-request path."401 Client Error: Unauthorized for url: https://api.withpersona.com": "Your Persona API key is invalid or has been revoked. Create a new API key in your Persona dashboard, then reconnect.",+ "Persona API not enabled for this account": "Persona has not enabled this API for your account, so this table cannot sync. Your API key is fine. Ask Persona to enable the API, then turn this table's sync back on.","403 Client Error: Forbidden for url: https://api.withpersona.com": "Your Persona API key is missing the read permissions needed to sync this data. Grant the required access in your Persona dashboard, then reconnect.",}diff --git a/products/warehouse_sources/sources/persona/tests/test_persona.py b/products/warehouse_sources/sources/persona/tests/test_persona.pyindex 0c9eaacbae26..d2acdbcdac9d 100644--- a/products/warehouse_sources/sources/persona/tests/test_persona.py+++ b/products/warehouse_sources/sources/persona/tests/test_persona.py@@ -12,6 +12,7 @@ from products.warehouse_sources.sources.persona import personafrom products.warehouse_sources.sources.persona.persona import (PERSONA_API_VERSION_2026_09_29,PERSONA_BASE_URL,+ PersonaApiNotEnabledError,PersonaRedirectError,PersonaResumeConfig,PersonaRetryableError,@@ -84,18 +85,31 @@ class TestFetchPageRetryClassification:# tenacity retries 5 times before giving up.assert session.get.call_count == 5- @parameterized.expand([("unauthorized", 401), ("forbidden", 403), ("not_found", 404)])- def test_client_errors_raise_immediately(self, _name: str, status: int) -> None:+ @parameterized.expand(+ [+ ("unauthorized", 401, None, requests.HTTPError),+ ("forbidden", 403, None, requests.HTTPError),+ ("forbidden_missing_scope", 403, {"errors": [{"title": "Forbidden"}]}, requests.HTTPError),+ (+ "forbidden_api_not_enabled",+ 403,+ {"errors": [{"title": "Forbidden", "details": "Workflows API is not enabled"}]},+ PersonaApiNotEnabledError,+ ),+ ("not_found", 404, None, requests.HTTPError),+ ]+ )+ def test_client_errors_raise_immediately(+ self, _name: str, status: int, body: dict | None, expected: type[requests.HTTPError]+ ) -> None:# Auth/permission errors can never be fixed by retrying, so they must surface at once.- response = requests.Response()- response.status_code = status- response.url = "https://api.withpersona.com/api/v1/inquiries"- session = MagicMock()- session.get.return_value = response-- with pytest.raises(requests.HTTPError):- persona._fetch_page(session, "https://api.withpersona.com/api/v1/inquiries", {}, MagicMock())- assert session.get.call_count == 1+ url = "https://api.withpersona.com/api/v1/workflow-runs"+ with requests_mock.Mocker() as m:+ m.get(url, status_code=status, json=body)+ with pytest.raises(requests.HTTPError) as raised:+ persona._fetch_page(requests.Session(), url, {}, MagicMock())+ assert m.call_count == 1+ assert type(raised.value) is expectedclass TestRedirectsRefused: