: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): stop sending an unsupported createdAt filter to dispute search (#96683)
posthog[bot]243d500d6807
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 b1e2b778a11a..1258733ae523 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@@ -152,9 +152,19 @@ def get_rows(search_input: dict[str, Any] = {}if should_use_incremental_field and db_incremental_field_last_value is not None:- # `greaterThanOrEqualTo` re-fetches the boundary row (merge dedupes on- # primary key) so records sharing the watermark are never skipped.- search_input = {"createdAt": {"greaterThanOrEqualTo": _format_created_at(db_incremental_field_last_value)}}+ if config.created_at_search_field is None:+ # The search input can't express the cursor, so the run re-reads everything+ # and the primary-key merge dedupes. Sending the filter anyway fails the+ # whole sync on a GraphQL validation error.+ logger.debug(f"Braintree: {endpoint} search input cannot filter on createdAt, re-reading all rows")+ else:+ # `greaterThanOrEqualTo` re-fetches the boundary row (merge dedupes on+ # primary key) so records sharing the watermark are never skipped.+ search_input = {+ config.created_at_search_field: {+ "greaterThanOrEqualTo": _format_created_at(db_incremental_field_last_value)+ }+ }resume_config = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else Noneafter: Optional[str] = resume_config.after if resume_config is not None else Nonediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.pyindex 9ae0951d3650..12fb8a03f4f0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py@@ -1,4 +1,6 @@-from dataclasses import dataclass, field+from dataclasses import field++from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType@@ -45,7 +47,7 @@ _DISPUTE_FIELDS = """"""-@dataclass+@frozenclass BraintreeEndpointConfig:# Field on the GraphQL `search` root.search_field: str@@ -55,12 +57,19 @@ class BraintreeEndpointConfig:primary_key: str = "id"incremental_fields: list[IncrementalField] = field(default_factory=lambda: list(_CREATED_AT_INCREMENTAL_FIELDS))partition_key: str = "createdAt"+ # Field on `input_type` that filters on the node's `createdAt`, or None when the+ # vendor's search input declares no equivalent. Sending a field the input type+ # doesn't define is a GraphQL validation error, not an ignored filter.+ created_at_search_field: str | None = "createdAt"-# Braintree's GraphQL search supports createdAt range filters on these-# streams, giving genuine server-side incremental. Result ordering is not-# documented, so incremental streams declare sort_mode="desc" — the pipeline-# then commits the watermark only when a run completes.+# `TransactionSearchInput` and `RefundSearchInput` both accept a createdAt range+# filter, giving those streams genuine server-side incremental. `DisputeSearchInput`+# does not (it filters on receivedDate/replyByDate/effectiveDate instead), so disputes+# re-read the full set each run and rely on the primary-key merge to dedupe — the node+# still exposes createdAt, so the incremental cursor and partition key are unchanged.+# Result ordering is not documented, so incremental streams declare sort_mode="desc" —+# the pipeline then commits the watermark only when a run completes.BRAINTREE_ENDPOINTS: dict[str, BraintreeEndpointConfig] = {"transactions": BraintreeEndpointConfig(search_field="transactions",@@ -76,6 +85,7 @@ BRAINTREE_ENDPOINTS: dict[str, BraintreeEndpointConfig] = {search_field="disputes",input_type="DisputeSearchInput",node_fields=_DISPUTE_FIELDS,+ created_at_search_field=None,),}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 ae52e1f7bf8e..c15f8eb1ced0 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@@ -162,6 +162,30 @@ class TestGetRows:variables = mock_session.return_value.post.call_args.kwargs["json"]["variables"]assert variables["input"] == {"createdAt": {"greaterThanOrEqualTo": "2024-01-02T00:00:00Z"}}+ @mock.patch(f"{_MODULE}.make_tracked_session")+ def test_incremental_omits_filter_when_search_input_lacks_created_at(self, mock_session):+ mock_session.return_value.post.return_value = _search_response("disputes", [])++ manager = _make_manager()+ list(+ get_rows(+ "production",+ "pub",+ "priv",+ "disputes",+ _VERSION,+ mock.MagicMock(),+ manager,+ should_use_incremental_field=True,+ db_incremental_field_last_value=datetime(2024, 1, 2, tzinfo=UTC),+ )+ )++ # `DisputeSearchInput` declares no createdAt field, so filtering on it fails+ # GraphQL validation and takes the whole sync down.+ variables = mock_session.return_value.post.call_args.kwargs["json"]["variables"]+ assert variables["input"] == {}+@mock.patch(f"{_MODULE}.make_tracked_session")def test_full_scan_has_empty_input(self, mock_session):mock_session.return_value.post.return_value = _search_response("transactions", [])