: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(data-imports): stop sending unsupported query params to Recurly gift_cards (#107761)
Tom Owers28219fe95b70
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/recurly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/recurly.pyindex 75b8f3f29852..e0f3ad4127ac 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/recurly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/recurly.py@@ -132,23 +132,28 @@ def get_resource(config = RECURLY_ENDPOINTS[endpoint]incremental = should_use_incremental_field and config.supports_incremental- if incremental:- # Sort by the cursor the user chose so `begin_time` and the watermark agree.- # Ascending order is mandatory: Recurly warns that descending `updated_at`- # lets concurrently-updated rows slip behind the cursor and never return.- sort_field = incremental_field if incremental_field in VALID_SORT_FIELDS else DEFAULT_SORT_FIELD+ if not config.supports_list_params:+ # This endpoint 400s on any query parameter, so it can't be paginated with a+ # `limit`, sorted, or filtered by `begin_time` — just take whatever Recurly returns.+ params: dict[str, Any] = {}else:- # Full refresh: a stable ascending `created_at` sort avoids page-boundary- # skips/duplicates if rows are inserted mid-sync.- sort_field = "created_at"-- params: dict[str, Any] = {- "limit": PAGE_LIMIT,- "sort": sort_field,- "order": "asc",- }- if incremental and db_incremental_field_last_value is not None:- params["begin_time"] = _format_datetime(db_incremental_field_last_value)+ if incremental:+ # Sort by the cursor the user chose so `begin_time` and the watermark agree.+ # Ascending order is mandatory: Recurly warns that descending `updated_at`+ # lets concurrently-updated rows slip behind the cursor and never return.+ sort_field = incremental_field if incremental_field in VALID_SORT_FIELDS else DEFAULT_SORT_FIELD+ else:+ # Full refresh: a stable ascending `created_at` sort avoids page-boundary+ # skips/duplicates if rows are inserted mid-sync.+ sort_field = "created_at"++ params = {+ "limit": PAGE_LIMIT,+ "sort": sort_field,+ "order": "asc",+ }+ if incremental and db_incremental_field_last_value is not None:+ params["begin_time"] = _format_datetime(db_incremental_field_last_value)return {"name": endpoint,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/settings.pyindex 28abb2dcde38..77681e3361a2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/settings.py@@ -12,7 +12,7 @@ RECURLY_BASE_URLS: dict[str, str] = {RECURLY_PARTITION_KEY = "created_at"-@dataclass+@dataclass(frozen=True)class RecurlyEndpoint:name: strpath: str@@ -21,6 +21,10 @@ class RecurlyEndpoint:# Endpoints that only accept `sort` (no time filter) stay full-refresh, since an# "incremental" sync would still read every page.supports_incremental: bool+ # `gift_cards` is the one list endpoint the v2021-02-25 OpenAPI spec gives zero query+ # parameters at all — no `limit`, `sort`, `order`, or `begin_time`. Recurly rejects the+ # request with a 400 validation error if any are sent, so it can only ever be listed bare.+ supports_list_params: bool = TrueRECURLY_ENDPOINTS: dict[str, RecurlyEndpoint] = {@@ -31,7 +35,7 @@ RECURLY_ENDPOINTS: dict[str, RecurlyEndpoint] = {"credit_payments": RecurlyEndpoint("credit_payments", "/credit_payments", True),"dunning_campaigns": RecurlyEndpoint("dunning_campaigns", "/dunning_campaigns", False),"external_subscriptions": RecurlyEndpoint("external_subscriptions", "/external_subscriptions", False),- "gift_cards": RecurlyEndpoint("gift_cards", "/gift_cards", True),+ "gift_cards": RecurlyEndpoint("gift_cards", "/gift_cards", False, supports_list_params=False),"invoices": RecurlyEndpoint("invoices", "/invoices", True),"items": RecurlyEndpoint("items", "/items", True),"line_items": RecurlyEndpoint("line_items", "/line_items", True),diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/tests/test_recurly.py b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/tests/test_recurly.pyindex 5bf8ffb26539..1a99cc0bb773 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/tests/test_recurly.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/recurly/tests/test_recurly.py@@ -22,6 +22,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.recurly.seINCREMENTAL_ENDPOINTS = [name for name, e in RECURLY_ENDPOINTS.items() if e.supports_incremental]FULL_REFRESH_ENDPOINTS = [name for name, e in RECURLY_ENDPOINTS.items() if not e.supports_incremental]+NO_LIST_PARAMS_ENDPOINTS = [name for name, e in RECURLY_ENDPOINTS.items() if not e.supports_list_params]def _list_body(data: list[dict[str, Any]], has_more: bool = False, next_path: str | None = None) -> dict[str, Any]:@@ -209,7 +210,9 @@ class TestGetResource:)assert "begin_time" not in resource["endpoint"]["params"]- @pytest.mark.parametrize("endpoint", FULL_REFRESH_ENDPOINTS)+ @pytest.mark.parametrize(+ "endpoint", [e for e in FULL_REFRESH_ENDPOINTS if RECURLY_ENDPOINTS[e].supports_list_params]+ )def test_full_refresh_endpoint_ignores_incremental_request(self, endpoint):# Even if the pipeline asks for incremental, an endpoint without a server-side# time filter must stay full-refresh.@@ -223,6 +226,23 @@ class TestGetResource:assert resource["endpoint"]["params"]["sort"] == "created_at"assert "begin_time" not in resource["endpoint"]["params"]+ @pytest.mark.parametrize("endpoint", NO_LIST_PARAMS_ENDPOINTS)+ @pytest.mark.parametrize("should_use_incremental_field", [True, False])+ def test_endpoint_without_list_params_sends_no_query_params(+ self, endpoint: str, should_use_incremental_field: bool+ ) -> None:+ # gift_cards' list endpoint 400s on any query parameter at all (confirmed against+ # the v2021-02-25 OpenAPI spec, which declares none for it), so limit/sort/order+ # must never be sent even when the pipeline asks for incremental.+ resource = _resource(+ endpoint,+ should_use_incremental_field=should_use_incremental_field,+ incremental_field="updated_at",+ db_incremental_field_last_value=datetime(2024, 1, 1, tzinfo=UTC),+ )+ assert resource["endpoint"]["params"] == {}+ assert resource["write_disposition"] == "replace"+def _make_http_response(body: dict[str, Any], status_code: int = 200) -> Response:resp = Response()