Skip to content

: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.

feat(data-warehouse): add 2 missing tables to the UpPromote source (#117334)

Tom Owers8c53716126bc
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
index 720e8c70b36e..b4a8bc61215a 100644
--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
@@ -1184,7 +1184,6 @@
1 products/warehouse_sources/backend/temporal/data_imports/sources/unleash/unleash.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/unstructured/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/unstructured/unstructured.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/uppromote.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/upstash/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/uptimerobot/settings.py
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.md
index 82473ede7cc1..ca1823563e79 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
@@ -12715,8 +12715,8 @@ Today (6): `affiliates`, `coupons`, `payments_paid`, `payments_unpaid`, `program
Diffed against: <https://aff-api.uppromote.com/docs/v2/llms.txt>
-- [ ] `connected customers (GET connected customer list)` — the customer-to-affiliate mapping — the lookup that lets referrals and payments be attributed back to individual customers (high)
-- [ ] `program excluded products/collections` — per-program commission exclusions, needed to explain why some orders generate no referral (low)
+- [x] `connected customers (GET connected customer list)` — the customer-to-affiliate mapping — the lookup that lets referrals and payments be attributed back to individual customers (high)
+- [x] `program excluded products/collections` — per-program commission exclusions, needed to explain why some orders generate no referral (low)
Note: The v2 public API is small; the llms.txt index lists every operation. Coverage is otherwise complete — the only unsynced read endpoints are the connected-customer list, a program config sub-resource, an aggregate count, and webhook subscriptions (config).
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/source_contract_baseline.txt b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/source_contract_baseline.txt
index 32f858cf2aa1..75026c4e82af 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/tests/source_contract_baseline.txt
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/tests/source_contract_baseline.txt
@@ -758,7 +758,7 @@ Ubidots fail:rate-limit-budget,safe-point,stall-budget
UkCompaniesHouse fail:stall-budget
Unleash fail:safe-point,stall-budget
Unstructured fail:rate-limit-budget,stall-budget
-UpPromote not-checkable:database
+UpPromote fail:stall-budget
Upstash fail:stall-budget
Uptimerobot fail:stall-budget
UsBea fail:rate-limit-budget,stall-budget
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/canonical_descriptions.py
index ffc41fc69a18..8d1e7c128dde 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/canonical_descriptions.py
@@ -140,4 +140,31 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"referral_ids": "IDs of the referrals awaiting payment.",
},
},
+ "connected_customers": {
+ "description": (
+ "A customer connected to an affiliate, either through a lifetime commission order or "
+ "added by the merchant. Links customers to the affiliate who earns commission on them."
+ ),
+ "docs_url": "https://aff-api.uppromote.com/docs/v2/get-connected-customer-list-40931610e0",
+ "columns": {
+ "affiliate_id": "ID of the affiliate the customer is connected to.",
+ "affiliate_email": "Email of the affiliate.",
+ "customer_id": "Shopify customer ID. Null for customers without a Shopify ID.",
+ "customer_email": "Email of the connected customer.",
+ "connection_date": "When the customer was connected.",
+ "connect_source": (
+ "How the customer was connected: lifetime (lifetime commission order) or manually "
+ "(added by the merchant or via the API)."
+ ),
+ },
+ },
+ "program_excluded": {
+ "description": "The products or collections excluded from commission in each affiliate program.",
+ "docs_url": "https://aff-api.uppromote.com/docs/v2/get-excluded-productscollections-of-a-program-28435011e0",
+ "columns": {
+ "program_id": "ID of the program the exclusions apply to.",
+ "apply_to": "Type of the excluded items (e.g. products or collections).",
+ "apply_to_ids": "Shopify IDs of the excluded products or collections.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/settings.py
index 65fbaf65e96c..b35adfc54f09 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/settings.py
@@ -1,6 +1,9 @@
from dataclasses import dataclass, field
from typing import Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
UPPROMOTE_BASE_URL = "https://aff-api.uppromote.com/api/v2"
@@ -28,7 +31,7 @@ UPPROMOTE_OBJECT_TYPE_TO_EVENTS: dict[str, tuple[str, ...]] = {
}
-@dataclass
+@dataclass(frozen=False)
class UpPromoteEndpointConfig:
name: str
path: str
@@ -42,6 +45,15 @@ class UpPromoteEndpointConfig:
incremental_fields: list[IncrementalField] = field(default_factory=list)
# Stable creation-time field used for datetime partitioning; never a mutable timestamp.
partition_key: Optional[str] = None
+ fanout: Optional[DependentEndpointConfig] = None
+
+ @property
+ def default_incremental_field(self) -> Optional[str]:
+ return self.incremental_fields[0]["field"] if self.incremental_fields else None
+
+ @property
+ def page_size(self) -> int:
+ return UPPROMOTE_PAGE_SIZE
_CREATED_AT_FIELD: IncrementalField = {
@@ -51,6 +63,13 @@ _CREATED_AT_FIELD: IncrementalField = {
"field_type": IncrementalFieldType.DateTime,
}
+_CONNECTION_DATE_FIELD: IncrementalField = {
+ "label": "connection_date",
+ "type": IncrementalFieldType.DateTime,
+ "field": "connection_date",
+ "field_type": IncrementalFieldType.DateTime,
+}
+
_PROCESSED_AT_FIELD: IncrementalField = {
"label": "processed_at",
"type": IncrementalFieldType.DateTime,
@@ -105,6 +124,35 @@ UPPROMOTE_ENDPOINTS: dict[str, UpPromoteEndpointConfig] = {
primary_keys=["affiliate_id"],
partition_key=None,
),
+ "connected_customers": UpPromoteEndpointConfig(
+ # Rows carry no id. `customer_id` is null for customers without a Shopify id, so the
+ # always-present email identifies the customer within an affiliate.
+ name="connected_customers",
+ path="/connected-customers",
+ primary_keys=["affiliate_id", "customer_email"],
+ supports_date_window=True,
+ requires_to_date=True,
+ incremental_fields=[_CONNECTION_DATE_FIELD],
+ partition_key="connection_date",
+ ),
+ "program_excluded": UpPromoteEndpointConfig(
+ # One object per program ({apply_to, apply_to_ids}) with no id or timestamp, so it's a
+ # full-refresh fan-out keyed on the parent program.
+ name="program_excluded",
+ path="/programs/{id}/excluded",
+ primary_keys=["program_id"],
+ partition_key=None,
+ fanout=DependentEndpointConfig(
+ parent_name="programs",
+ resolve_param="id",
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": "program_id"},
+ parent_params={"per_page": UPPROMOTE_PAGE_SIZE},
+ # A program deleted between the parent page and its child request must not fail the sync.
+ child_response_actions=[{"status_code": 404, "action": "ignore"}],
+ ),
+ ),
}
ENDPOINTS = tuple(UPPROMOTE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/source.py
index 79d4276d5486..389b25382a1c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/source.py
@@ -175,6 +175,10 @@ class UpPromoteSource(
"Outstanding (approved but unpaid) commission per affiliate. An aggregated "
"snapshot, refreshed in full on every sync"
),
+ "program_excluded": (
+ "Products or collections excluded from commission, one row per program. "
+ "Refreshed in full on every sync"
+ ),
},
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/tests/test_uppromote.py b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/tests/test_uppromote.py
index a4251b17646a..847af9d1d441 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/tests/test_uppromote.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/tests/test_uppromote.py
@@ -12,6 +12,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.tes
ScriptedResponse,
SourceDriver,
always,
+ route,
scripted_network,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManager
@@ -111,6 +112,47 @@ class TestUpPromoteSourcePagination:
assert result.params("page") == ["1"]
+ @parameterized.expand(
+ [
+ # Both endpoints reject `from_date` without `to_date` with a 422.
+ ("referrals", "created_at", "2026-01-01T00:00:10Z", "2026-01-01T00:00:09Z", True),
+ ("connected_customers", "connection_date", "2026-01-01T00:00:10Z", "2026-01-01T00:00:09Z", True),
+ ("affiliates", "created_at", "2026-01-01T00:00:10Z", "2026-01-01T00:00:09Z", False),
+ # A first incremental run has no watermark and pulls everything.
+ ("connected_customers", "connection_date", None, None, False),
+ ]
+ )
+ def test_incremental_window_params(
+ self,
+ endpoint: str,
+ incremental_field: str,
+ last_value: str | None,
+ expected_from_date: str | None,
+ expects_to_date: bool,
+ ) -> None:
+ result = _driver().run(
+ endpoint,
+ [_page([{"id": 1}]), _page([])],
+ incremental_field=incremental_field,
+ db_incremental_field_last_value=last_value,
+ )
+
+ assert result.params("page") == ["1", "2"]
+ assert result.params("from_date") == [expected_from_date] * 2
+ to_dates = result.params("to_date")
+ if expects_to_date:
+ assert to_dates[0] is not None
+ # The window end stays frozen across the pages of one run.
+ assert to_dates == [to_dates[0]] * 2
+ else:
+ assert to_dates == [None, None]
+
+ def test_full_refresh_sends_no_window(self) -> None:
+ result = _driver().run("connected_customers", [_page([{"affiliate_id": 1}]), _page([])])
+
+ assert result.params("from_date") == [None, None]
+ assert result.params("to_date") == [None, None]
+
@parameterized.expand(
[
("programs", ["id"]),
@@ -142,6 +184,58 @@ class TestUpPromoteSourcePagination:
assert "table_transformer" in webhook_manager.get_items.call_args.kwargs
+class TestProgramExcludedFanout:
+ def test_fans_out_over_every_program_page_and_tags_rows_with_the_program(self) -> None:
+ result = _driver().run(
+ "program_excluded",
+ route(
+ {
+ "/programs": [_page([{"id": 11}, {"id": 12}]), _page([{"id": 13}]), _page([])],
+ "/programs/11/excluded": [
+ ScriptedResponse(
+ json={
+ "status": 200,
+ "message": "success",
+ "data": {"apply_to": "products", "apply_to_ids": ["9001", "9002"]},
+ }
+ )
+ ],
+ # A program without exclusions returns no object and produces no row.
+ "/programs/12/excluded": [_page([])],
+ "/programs/13/excluded": [
+ ScriptedResponse(
+ json={
+ "status": 200,
+ "message": "success",
+ "data": {"apply_to": "collections", "apply_to_ids": []},
+ }
+ )
+ ],
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert sorted(result.rows, key=lambda row: row["program_id"]) == [
+ {"program_id": 11, "apply_to": "products", "apply_to_ids": ["9001", "9002"]},
+ {"program_id": 13, "apply_to": "collections", "apply_to_ids": []},
+ ]
+
+ child_requests = [request for request in result.requests if request.path.endswith("/excluded")]
+ assert [request.path for request in child_requests] == [
+ "/api/v2/programs/11/excluded",
+ "/api/v2/programs/12/excluded",
+ "/api/v2/programs/13/excluded",
+ ]
+ # The child endpoint is a single object, so it must not be paginated.
+ assert all(request.param("page") is None for request in child_requests)
+ assert all(request.param("per_page") is None for request in child_requests)
+
+ parent_requests = [request for request in result.requests if request.path == "/api/v2/programs"]
+ assert [request.param("page") for request in parent_requests] == ["1", "2", "3"]
+ assert all(request.headers["authorization"] == "test-key" for request in result.requests)
+
+
class TestWebhookTableTransformer:
def test_keeps_latest_row_per_key_and_drops_keyless_rows(self) -> None:
transform = _make_webhook_table_transformer("id")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/uppromote.py b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/uppromote.py
index 19d968191c4e..dffbeb12cce1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/uppromote.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/uppromote/uppromote.py
@@ -20,10 +20,17 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTAPIConfig,
rest_api_resource,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+ build_dependent_resource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
PageNumberPaginator,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ ClientConfig,
+ EndpointResource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManager
@@ -176,6 +183,58 @@ def _build_resource(
}
+def _client_config(api_key: str) -> ClientConfig:
+ return {
+ "base_url": UPPROMOTE_BASE_URL,
+ "auth": {
+ "type": "api_key",
+ "name": "Authorization",
+ "location": "header",
+ "api_key": api_key,
+ },
+ # Sync responses carry affiliate/referral PII (emails, addresses, payment
+ # details), so reuse the capture-disabled, key-redacting tracked session
+ # rather than letting RESTClient build its default capturing one.
+ "session": _make_session(api_key),
+ # No pagination metadata in responses — iterate pages until an empty one.
+ "paginator": PageNumberPaginator(base_page=1, page_param="page", stop_after_empty_page=True),
+ }
+
+
+def _fanout_source(
+ api_key: str,
+ config: UpPromoteEndpointConfig,
+ fanout: DependentEndpointConfig,
+ team_id: int,
+ job_id: str,
+) -> SourceResponse:
+ child = build_dependent_resource(
+ endpoint_configs=UPPROMOTE_ENDPOINTS,
+ child_endpoint=config.name,
+ fanout=fanout,
+ client_config=_client_config(api_key),
+ path_format_values={},
+ team_id=team_id,
+ job_id=job_id,
+ # The child endpoints have no date filter, so the fan-out is always a full refresh.
+ db_incremental_field_last_value=None,
+ parent_endpoint_extra={"data_selector": "data"},
+ # The child returns one unpaginated object per parent.
+ child_endpoint_extra={"data_selector": "data", "paginator": "single_page"},
+ # Page size is in the parent's `parent_params`; the child takes no `per_page`.
+ page_size_param=None,
+ )
+
+ return SourceResponse(
+ name=config.name,
+ items=lambda: child,
+ primary_keys=config.primary_keys,
+ sort_mode="asc",
+ # The fan-out saves no checkpoint, so every retry restarts the full refresh.
+ supports_resume=False,
+ )
+
+
def _make_webhook_table_transformer(primary_key: str) -> Callable[[pa.Table], pa.Table]:
"""Collapse a webhook batch to the latest version of each object.
@@ -208,6 +267,9 @@ def uppromote_source(
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = UPPROMOTE_ENDPOINTS[endpoint]
+ if config.fanout is not None:
+ return _fanout_source(api_key, config, config.fanout, team_id, job_id)
+
webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)()
resume_config = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
@@ -222,21 +284,7 @@ def uppromote_source(
)
rest_config: RESTAPIConfig = {
- "client": {
- "base_url": UPPROMOTE_BASE_URL,
- "auth": {
- "type": "api_key",
- "name": "Authorization",
- "location": "header",
- "api_key": api_key,
- },
- # Sync responses carry affiliate/referral PII (emails, addresses, payment
- # details), so reuse the capture-disabled, key-redacting tracked session
- # rather than letting RESTClient build its default capturing one.
- "session": _make_session(api_key),
- # No pagination metadata in responses — iterate pages until an empty one.
- "paginator": PageNumberPaginator(base_page=1, page_param="page", stop_after_empty_page=True),
- },
+ "client": _client_config(api_key),
"resource_defaults": {},
"resources": [
_build_resource(config, should_use_incremental_field, db_incremental_field_last_value, window_end)