: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(braintree): declare search input as non-null in GraphQL query (#72717)
Tom Owers79973c72a8a4
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.pyindex 266e5091d75c..39a30421f5ff 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/braintree.py@@ -70,8 +70,10 @@ def _format_created_at(value: Any) -> str:def _build_query(config: BraintreeEndpointConfig) -> str:+ # Braintree's search fields declare `input` as non-null, even though every+ # field within the input type is optional (an empty object matches everything).return f"""-query ($input: {config.input_type}, $first: Int!, $after: String) {{+query ($input: {config.input_type}!, $first: Int!, $after: String) {{search {{{config.search_field} (input: $input, first: $first, after: $after) {{pageInfo {{ hasNextPage }}@@ -164,7 +166,7 @@ def get_rows(return _execute(session, url, query, variables, logger)while True:- data = execute({"input": search_input or None, "first": PAGE_SIZE, "after": after})+ data = execute({"input": search_input, "first": PAGE_SIZE, "after": after})connection = ((data.get("search") or {}).get(config.search_field)) or {}edges = connection.get("edges") or []items = [edge.get("node") for edge in edges if edge.get("node")]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.pyindex 03ce28e00f3d..f4a59269389b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/tests/test_braintree.py@@ -68,7 +68,9 @@ class TestBuildQuery:)def test_query_uses_correct_input_type(self, endpoint, input_type):query = _build_query(BRAINTREE_ENDPOINTS[endpoint])- assert f"$input: {input_type}" in query+ # Braintree's search fields declare `input` as non-null; a nullable+ # declaration here fails GraphQL validation (VariableTypeMismatch).+ assert f"$input: {input_type}!" in queryassert BRAINTREE_ENDPOINTS[endpoint].search_field in query@@ -154,14 +156,16 @@ class TestGetRows:assert variables["input"] == {"createdAt": {"greaterThanOrEqualTo": "2024-01-02T00:00:00Z"}}@mock.patch(f"{_MODULE}.make_tracked_session")- def test_full_scan_has_null_input(self, mock_session):+ def test_full_scan_has_empty_input(self, mock_session):mock_session.return_value.post.return_value = _search_response("transactions", [])manager = _make_manager()list(get_rows("production", "pub", "priv", "transactions", _VERSION, mock.MagicMock(), manager))+ # `input` is declared non-null (see TestBuildQuery), so a full scan must+ # send an empty object rather than null or Braintree rejects the query.variables = mock_session.return_value.post.call_args.kwargs["json"]["variables"]- assert variables["input"] is None+ assert variables["input"] == {}@mock.patch(f"{_MODULE}.make_tracked_session")def test_resumes_from_saved_cursor(self, mock_session):