: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(fillout): stop one unreadable form from blocking source setup (#113113)
Tom Owers2957e8d4a2c5
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.pyindex d02a4d1ca542..685b18d1d622 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/fillout.py@@ -131,6 +131,12 @@ class _PerFormProbe:label: str+# Fillout answers the per-form probe with a 400 or 404 when it can't load that one form, which+# says nothing about the key. Later forms stand in for it, up to a cap that keeps validation+# quick on accounts with many forms.+_FORM_SPECIFIC_PROBE_STATUSES = (400, 404)+_MAX_FORMS_TO_PROBE = 5+_PER_FORM_PROBES: dict[str, _PerFormProbe] = {"submissions": _PerFormProbe(path_suffix="/submissions", params={"limit": 1}, label="submissions"),"form_metadata": _PerFormProbe(path_suffix="", params={}, label="form metadata"),@@ -182,11 +188,11 @@ def validate_credentials(# With no forms there's nothing to probe against; that shouldn't block validation.if isinstance(forms_items, list) and forms_items:- first_form = forms_items[0]- form_id = first_form.get("formId") if isinstance(first_form, dict) else None- if not isinstance(form_id, str) or not form_id:- errors.append(f"Fillout returned an invalid form id while validating {probe.label} access.")- else:+ for form in forms_items[:_MAX_FORMS_TO_PROBE]:+ form_id = form.get("formId") if isinstance(form, dict) else None+ if not isinstance(form_id, str) or not form_id:+ errors.append(f"Fillout returned an invalid form id while validating {probe.label} access.")+ breaktry:probe_response = make_tracked_session().get(f"{base_url}/forms/{form_id}{probe.path_suffix}",@@ -194,16 +200,18 @@ def validate_credentials(params=probe.params,timeout=10,)- if probe_response.status_code == 401:- errors.append("Invalid Fillout API key")- elif probe_response.status_code == 403:- errors.append(f"Fillout API key is missing permission to read {probe.label}")- elif probe_response.status_code != 200:- errors.append(- f"Fillout {probe.label} endpoint failed: {_parse_error_description(probe_response)}"- )except RequestException as exc:errors.append(f"Fillout {probe.label} request failed: {exc}")+ break+ if probe_response.status_code in _FORM_SPECIFIC_PROBE_STATUSES:+ continue+ if probe_response.status_code == 401:+ errors.append("Invalid Fillout API key")+ elif probe_response.status_code == 403:+ errors.append(f"Fillout API key is missing permission to read {probe.label}")+ elif probe_response.status_code != 200:+ errors.append(f"Fillout {probe.label} endpoint failed: {_parse_error_description(probe_response)}")+ breakif errors:return False, "; ".join(errors)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.pyindex 0c363aaf4cf0..f7cb4525652a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fillout/tests/test_fillout.py@@ -144,6 +144,33 @@ class TestFilloutTransport:== "https://api.fillout.com/v1/api/forms/form_1/submissions")+ @parameterized.expand(+ [+ ("next_form_readable", [400, 200]),+ ("not_found_then_readable", [404, 200]),+ ("no_form_readable", [400, 400]),+ ]+ )+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.fillout.fillout.make_tracked_session")+ def test_validate_credentials_skips_a_form_fillout_cannot_serve(self, _name, probe_statuses, mock_session) -> None:+ forms_response = Mock(status_code=200, text="ok")+ forms_response.json.return_value = [{"formId": "form_1"}, {"formId": "form_2"}]+ probe_responses = []+ for status in probe_statuses:+ probe_response = Mock(status_code=status, text="form unavailable")+ probe_response.json.return_value = {"message": "form unavailable"}+ probe_responses.append(probe_response)+ mock_session.return_value.get.side_effect = [forms_response, *probe_responses]++ result = validate_credentials(api_key="key")++ assert result == (True, None)+ assert mock_session.return_value.get.call_count == 3+ assert [call.args[0] for call in mock_session.return_value.get.call_args_list[1:]] == [+ "https://api.fillout.com/v1/api/forms/form_1/submissions",+ "https://api.fillout.com/v1/api/forms/form_2/submissions",+ ]+@parameterized.expand([(401, "Invalid Fillout API key"),