: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
feat(data-warehouse): add 4 missing tables to the GoCardless source (#117006)
Tom Owers940ff0228096
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex 5da8105fe2b8..c6ed73145db6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -5362,10 +5362,10 @@ Diffed against: <https://developer.gocardless.com/api-reference/>- [x] `customer_bank_accounts` — lookup resolving the customer_bank_account IDs carried on every mandate and payment we already sync (high)- [x] `creditors` — lookup resolving the creditor ID on payments, payouts and mandates (high)- [x] `balances` — current available/pending funds per creditor - the headline treasury metric (medium)-- [ ] `instalment_schedules` — payment plans that group the individual payments we sync (medium)-- [ ] `billing_requests` — the modern checkout/mandate-setup funnel object, needed to measure setup conversion (medium)-- [ ] `payment_account_transactions` — transaction ledger for embedded payment accounts (medium)-- [ ] `outbound_payments` — money-out transactions, the counterpart to the payments table (medium)+- [x] `instalment_schedules` — payment plans that group the individual payments we sync (medium)+- [x] `billing_requests` — the modern checkout/mandate-setup funnel object, needed to measure setup conversion (medium)+- [x] `payment_account_transactions` — transaction ledger for embedded payment accounts (medium)+- [x] `outbound_payments` — money-out transactions, the counterpart to the payments table (medium)- [ ] `creditor_bank_accounts` — lookup resolving the destination bank account on payouts (medium)- [ ] `tax_rates` — lookup resolving the tax rate ID on payments and subscriptions (low)- [ ] `scheme_identifiers` — lookup resolving the scheme identifier referenced by mandates (low)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/canonical_descriptions.pyindex 71c5d398d1d4..da0aa8bee4db 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/canonical_descriptions.py@@ -161,4 +161,66 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"links": "Related resources (payment, mandate, refund).",},},+ "instalment_schedules": {+ "description": "A payment plan that collects a total amount from a customer as a series of payments.",+ "docs_url": "https://docs.gocardless.com/docs/api-reference/instalment-schedule",+ "columns": _columns(+ name="Name of the instalment schedule, shown to the customer.",+ status="State of the schedule (e.g. pending, active, creation_failed, completed, cancelled, errored).",+ total_amount="Total amount of all the instalments, in the smallest currency unit.",+ currency="ISO 4217 three-letter currency code of the instalments.",+ payment_errors="Validation errors for the instalments, if the schedule failed to be created.",+ links="Related resources (customer, mandate, and the payments the schedule created).",+ ),+ },+ "billing_requests": {+ "description": "A request to collect a mandate, a payment, or both from a customer, used to drive the checkout flow.",+ "docs_url": "https://docs.gocardless.com/docs/api-reference/billing-request",+ "columns": _columns(+ status="State of the billing request (pending, ready_to_fulfil, fulfilling, fulfilled, cancelled).",+ mandate_request="Details of the mandate that the billing request asks the customer to set up.",+ payment_request="Details of the one-off payment that the billing request asks the customer to make.",+ subscription_request="Details of the subscription that the billing request creates when fulfilled.",+ instalment_schedule_request="Details of the instalment schedule that the billing request creates when fulfilled.",+ actions="Actions that must be completed before the billing request can be fulfilled.",+ resources="Snapshot of the customer, bank account, and billing details collected so far.",+ fallback_enabled="Whether a failed bank payment can fall back to a mandate-based payment.",+ fallback_occurred="Whether the fallback to a mandate-based payment occurred.",+ purpose_code="Purpose of the mandate or payment, for schemes that require one.",+ links="Related resources (customer, creditor, mandate, payment, and others).",+ ),+ },+ "outbound_payments": {+ "description": "A payment sent from your GoCardless payment account to a recipient bank account.",+ "docs_url": "https://docs.gocardless.com/docs/api-reference/outbound-payment",+ "columns": _columns(+ amount="Amount of the outbound payment, in the smallest currency unit.",+ currency="ISO 4217 three-letter currency code of the outbound payment.",+ status="State of the outbound payment (e.g. pending_approval, scheduled, executing, executed, cancelled, failed).",+ execution_date="Date on which the outbound payment is executed.",+ scheme="Bank payment scheme used to send the outbound payment.",+ reference="Reference shown on the recipient's bank statement.",+ description="Description of the outbound payment.",+ is_withdrawal="Whether the outbound payment withdraws funds to your own bank account.",+ verifications="Results of the checks made on the recipient bank account.",+ links="Related resources (creditor, customer, recipient bank account).",+ ),+ },+ "payment_account_transactions": {+ "description": "A movement of funds into or out of a GoCardless payment account.",+ "docs_url": "https://docs.gocardless.com/docs/api-reference/payment-account-transaction",+ "columns": {+ "id": "Unique identifier for the transaction, beginning with a resource-type prefix.",+ "payment_account_id": "ID of the payment account the transaction belongs to.",+ "amount": "Amount of the transaction, in the smallest currency unit.",+ "balance_after_transaction": "Balance of the payment account after the transaction, in the smallest currency unit.",+ "currency": "ISO 4217 three-letter currency code of the transaction.",+ "direction": "Whether funds moved into (credit) or out of (debit) the payment account.",+ "counterparty_name": "Name of the other party in the transaction.",+ "description": "Description of the transaction.",+ "reference": "Reference of the transaction.",+ "value_date": "Date on which the transaction took effect on the balance.",+ "links": "Related resources (outbound payment, payout, payment bank account).",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/gocardless.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/gocardless.pyindex e5d8c3b833b0..295a36d057a8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/gocardless.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/gocardless.py@@ -23,7 +23,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.soufrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.gocardless.settings import (GOCARDLESS_ENDPOINTS,+ GOCARDLESS_FANOUT_PARENTS,PAGE_SIZE,+ VALUE_DATE_RANGE_START,)GOCARDLESS_HOSTS = {@@ -108,7 +110,8 @@ def _fanout_source(base_url: str, access_token: str, endpoint: str, team_id: intconfig = GOCARDLESS_ENDPOINTS[endpoint]assert config.fanout is not Nonefanout = config.fanout- parent_config = GOCARDLESS_ENDPOINTS[fanout.parent_name]+ endpoint_configs = {**GOCARDLESS_ENDPOINTS, **GOCARDLESS_FANOUT_PARENTS}+ parent_config = endpoint_configs[fanout.parent_name]if config.parent_created_within_days is not None:cutoff = datetime.now(UTC) - timedelta(days=config.parent_created_within_days)@@ -116,10 +119,19 @@ def _fanout_source(base_url: str, access_token: str, endpoint: str, team_id: intfanout, parent_params={**fanout.parent_params, "created_at[gte]": _format_created_at(cutoff)})+ child_params_extra: Optional[dict[str, Any]] = None+ if config.requires_value_date_range:+ # A day past today in UTC still covers a transaction that is already dated tomorrow in UK time.+ range_end = datetime.now(UTC).date() + timedelta(days=1)+ child_params_extra = {+ "value_date_from": VALUE_DATE_RANGE_START.isoformat(),+ "value_date_to": range_end.isoformat(),+ }+dependent_resource = cast(Iterable[Any],build_dependent_resource(- endpoint_configs=GOCARDLESS_ENDPOINTS,+ endpoint_configs=endpoint_configs,child_endpoint=endpoint,fanout=fanout,client_config=_client_config(base_url, access_token),@@ -130,6 +142,7 @@ def _fanout_source(base_url: str, access_token: str, endpoint: str, team_id: intshould_use_incremental_field=False,parent_endpoint_extra={"paginator": GoCardlessCursorPaginator(), "data_selector": parent_config.data_key},child_endpoint_extra={"paginator": GoCardlessCursorPaginator(), "data_selector": config.data_key},+ child_params_extra=child_params_extra,),)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/settings.pyindex a4a34fe7ac1b..231d506d80b8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/settings.py@@ -1,4 +1,5 @@from dataclasses import dataclass, field+from datetime import datefrom typing import Optionalfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (@@ -9,6 +10,10 @@ from products.warehouse_sources.backend.types import IncrementalField, Increment# GoCardless list pages cap at 500 items.PAGE_SIZE = 500+# Lower bound of the value date range that a full listing asks for. GoCardless provisioned no+# payment account before this date, so the range covers every transaction.+VALUE_DATE_RANGE_START = date(2015, 1, 1)+@dataclass(frozen=True)class GoCardlessEndpointConfig:@@ -26,6 +31,8 @@ class GoCardlessEndpointConfig:fanout: Optional[DependentEndpointConfig] = None# Bounds the fan-out parent listing to rows created in the last N days.parent_created_within_days: Optional[int] = None+ # The list endpoint rejects a request without value_date_from and value_date_to.+ requires_value_date_range: bool = False# GoCardless list endpoints filter only on created_at (no updated_at), and core@@ -123,6 +130,47 @@ GOCARDLESS_ENDPOINTS: dict[str, GoCardlessEndpointConfig] = {),parent_created_within_days=186,),+ "instalment_schedules": GoCardlessEndpointConfig(+ name="instalment_schedules",+ path="/instalment_schedules",+ data_key="instalment_schedules",+ ),+ "billing_requests": GoCardlessEndpointConfig(+ name="billing_requests",+ path="/billing_requests",+ data_key="billing_requests",+ ),+ "outbound_payments": GoCardlessEndpointConfig(+ name="outbound_payments",+ path="/outbound_payments",+ data_key="outbound_payments",+ ),+ # Transactions are listed per payment account only, so they fan out over /payment_accounts.+ # A transaction has a value_date but no created_at, so the table is not partitioned.+ "payment_account_transactions": GoCardlessEndpointConfig(+ name="payment_account_transactions",+ path="/payment_accounts/{payment_account}/transactions",+ data_key="payment_account_transactions",+ partition_key=None,+ requires_value_date_range=True,+ fanout=DependentEndpointConfig(+ parent_name="payment_accounts",+ resolve_param="payment_account",+ resolve_field="id",+ include_from_parent=["id"],+ parent_field_renames={"id": "payment_account_id"},+ ),+ ),+}++# Fan-out parents that are not offered as tables of their own.+GOCARDLESS_FANOUT_PARENTS: dict[str, GoCardlessEndpointConfig] = {+ "payment_accounts": GoCardlessEndpointConfig(+ name="payment_accounts",+ path="/payment_accounts",+ data_key="payment_accounts",+ partition_key=None,+ ),}ENDPOINTS = tuple(GOCARDLESS_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/tests/test_gocardless.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/tests/test_gocardless.pyindex 8c6d7d4a7001..324649285bc0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/tests/test_gocardless.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gocardless/tests/test_gocardless.py@@ -2,6 +2,7 @@ from datetime import UTC, date, datetimefrom typing import Anyimport pytest+import time_machinefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.testing import (ScriptedResponse,@@ -141,10 +142,33 @@ class TestFanout:assert result.raised is Noneassert result.paths[1] == f"/{endpoint}"assert result.requests[1].param(resolve_param) == parent_id+ assert result.requests[1].param("value_date_from") is Noneassert result.requests[2].param("after") == "X1"assert [row["type"] for row in result.rows] == ["a", "b"]assert all(row[injected_key] == parent_id for row in result.rows)+ @time_machine.travel(datetime(2026, 3, 31, 23, 30, tzinfo=UTC), tick=False)+ def test_payment_account_transactions_are_fetched_per_account_with_value_date_range(self) -> None:+ result = _driver().run(+ "payment_account_transactions",+ [+ _page("payment_accounts", [{"id": "BA1"}]),+ _page("payment_account_transactions", [{"id": "PATR1"}], after="PATR1"),+ _page("payment_account_transactions", [{"id": "PATR2"}]),+ ],+ )++ assert result.raised is None+ assert result.paths == [+ "/payment_accounts",+ "/payment_accounts/BA1/transactions",+ "/payment_accounts/BA1/transactions",+ ]+ assert result.params("value_date_from") == [None, "2015-01-01", "2015-01-01"]+ assert result.params("value_date_to") == [None, "2026-04-01", "2026-04-01"]+ assert result.requests[2].param("after") == "PATR1"+ assert [(row["id"], row["payment_account_id"]) for row in result.rows] == [("PATR1", "BA1"), ("PATR2", "BA1")]+def test_balances_lists_every_creditor(self) -> None:result = _driver().run("balances", [_page("creditors", [{"id": "CR1"}]), _page("balances", [])])@@ -163,11 +187,10 @@ class TestGoCardlessSourceResponse:response = result.responseassert response is not Noneassert response.name == endpoint- if config.primary_key is None:- assert response.primary_keys is None+ assert response.primary_keys == ([config.primary_key] if config.primary_key else None)+ if config.partition_key is None:assert response.partition_keys is Nonereturn- assert response.primary_keys == [config.primary_key]assert response.partition_mode == "datetime"assert response.partition_keys == ["created_at"]# Lists are reverse-chronological; only the incremental events stream