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 4 missing tables to the Buttondown source (#117476)

Tom Owersff4076f02f6f
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 888189a85e02..30bb3521adce 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
@@ -2038,10 +2038,10 @@ Today (10): `automations`, `comments`, `emails`, `events`, `forms`, `prices`, `s
Diffed against: <https://docs.buttondown.com/openapi.json>
-- [ ] `Stripe subscriptions (GET /v1/subscribers/{id_or_email}/stripe-subscriptions)` — analyze paid subscription history, recurring revenue, cancellations, and billing cadence (high)
-- [ ] `Referrals (GET /v1/subscribers/{id_or_email}/referrals)` — attribute subscriber growth to specific referring subscribers (medium)
-- [ ] `Subscriber automation attempts (GET /v1/subscribers/{id_or_email}/automations)` — analyze automation completion, skipped attempts, errors, and scheduled execution for each subscriber (medium)
-- [ ] `Notes (GET /v1/notes)` — track dated notes attached to subscribers, emails, and other analytical objects (medium)
+- [x] `Stripe subscriptions (GET /v1/subscribers/{id_or_email}/stripe-subscriptions)` — analyze paid subscription history, recurring revenue, cancellations, and billing cadence (high)
+- [x] `Referrals (GET /v1/subscribers/{id_or_email}/referrals)` — attribute subscriber growth to specific referring subscribers (medium)
+- [x] `Subscriber automation attempts (GET /v1/subscribers/{id_or_email}/automations)` — analyze automation completion, skipped attempts, errors, and scheduled execution for each subscriber (medium)
+- [x] `Notes (GET /v1/notes)` — track dated notes attached to subscribers, emails, and other analytical objects (medium)
- [ ] `Segments (GET /v1/segments)` — analyze saved audiences and compare their targeting rules with email performance (medium)
- [ ] `Coupons (GET /v1/coupons)` — analyze the complete discount catalog alongside paid subscriptions and subscriber promotions (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/buttondown.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/buttondown.py
index ed8ea842dd07..518f07d783a8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/buttondown.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/buttondown.py
@@ -1,16 +1,28 @@
-import dataclasses
from datetime import date, datetime, timedelta
-from typing import Any, Optional
+from typing import Any, Optional, cast
-from products.warehouse_sources.backend.temporal.data_imports.sources.buttondown.settings import BUTTONDOWN_ENDPOINTS
+from posthog.dataclasses import frozen
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.buttondown.settings import (
+ BUTTONDOWN_ENDPOINTS,
+ ButtondownEndpointConfig,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
RESTAPIConfig,
rest_api_resource,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_dependent_resource,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponsePaginator,
)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
+ ClientConfig,
+ Endpoint,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -21,11 +33,14 @@ BUTTONDOWN_BASE_URL = "https://api.buttondown.com/v1"
BUTTONDOWN_API_VERSION = "2026-04-01"
+@frozen
class ButtondownResumeConfig:
# Absolute URL of the next unfetched page. Buttondown paginates DRF-style: each page body carries
# a fully-formed `next` link (or null on the last page).
- next_url: str
+ next_url: Optional[str] = None
+ # Per-subscriber endpoints checkpoint the fan-out instead: the subscribers already done and the
+ # child page of the one in progress.
+ fanout_state: Optional[dict[str, Any]] = None
def _headers(api_version: str) -> dict[str, str]:
@@ -58,18 +73,33 @@ def _to_start_date(value: Any) -> Optional[str]:
return (day - timedelta(days=1)).isoformat()
-def buttondown_source(
- api_key: str,
- endpoint: str,
+def _client_config(api_key: str, api_version: str) -> ClientConfig:
+ return {
+ "base_url": BUTTONDOWN_BASE_URL,
+ "headers": _headers(api_version),
+ "auth": {
+ "type": "api_key",
+ "name": "Authorization",
+ # Buttondown requires the literal "Token " prefix, not "Bearer ".
+ "api_key": f"Token {api_key}",
+ "location": "header",
+ },
+ "paginator": JSONResponsePaginator(next_url_path="next"),
+ # Pagination follows absolute `next` links straight out of the response body, so pin
+ # them to the API host: a spoofed link would otherwise replay the API key elsewhere.
+ "allowed_hosts": [],
+ }
+
+
+def _top_level_resource(
+ config: ButtondownEndpointConfig,
+ client_config: ClientConfig,
team_id: int,
job_id: str,
resumable_source_manager: ResumableSourceManager[ButtondownResumeConfig],
- api_version: str = BUTTONDOWN_API_VERSION,
- db_incremental_field_last_value: Optional[Any] = None,
- should_use_incremental_field: bool = False,
-) -> SourceResponse:
- config = BUTTONDOWN_ENDPOINTS[endpoint]
-
+ db_incremental_field_last_value: Optional[Any],
+ should_use_incremental_field: bool,
+) -> Resource:
params: dict[str, Any] = {}
if config.ordering is not None:
params["ordering"] = config.ordering
@@ -82,25 +112,11 @@ def buttondown_source(
}
rest_config: RESTAPIConfig = {
- "client": {
- "base_url": BUTTONDOWN_BASE_URL,
- "headers": _headers(api_version),
- "auth": {
- "type": "api_key",
- "name": "Authorization",
- # Buttondown requires the literal "Token " prefix, not "Bearer ".
- "api_key": f"Token {api_key}",
- "location": "header",
- },
- "paginator": JSONResponsePaginator(next_url_path="next"),
- # Pagination follows absolute `next` links straight out of the response body, so pin
- # them to the API host: a spoofed link would otherwise replay the API key elsewhere.
- "allowed_hosts": [],
- },
+ "client": client_config,
"resource_defaults": {},
"resources": [
{
- "name": endpoint,
+ "name": config.name,
"write_disposition": {"disposition": "merge", "strategy": "upsert"}
if should_use_incremental_field
else "replace",
@@ -120,7 +136,7 @@ def buttondown_source(
initial_paginator_state: Optional[dict[str, Any]] = None
if resumable_source_manager.can_resume():
resume = resumable_source_manager.load_state()
- if resume is not None:
+ if resume is not None and resume.next_url:
initial_paginator_state = {"next_url": resume.next_url}
def save_checkpoint(state: Optional[dict[str, Any]]) -> None:
@@ -129,7 +145,7 @@ def buttondown_source(
if state and state.get("next_url"):
resumable_source_manager.save_state(ButtondownResumeConfig(next_url=str(state["next_url"])))
- resource = rest_api_resource(
+ return rest_api_resource(
rest_config,
team_id,
job_id,
@@ -138,6 +154,73 @@ def buttondown_source(
initial_paginator_state=initial_paginator_state,
)
+
+def _fanout_resource(
+ config: ButtondownEndpointConfig,
+ client_config: ClientConfig,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[ButtondownResumeConfig],
+) -> Resource:
+ assert config.fanout is not None
+
+ initial_paginator_state: Optional[dict[str, Any]] = None
+ if resumable_source_manager.can_resume():
+ resume = resumable_source_manager.load_state()
+ if resume is not None and resume.fanout_state:
+ initial_paginator_state = resume.fanout_state
+
+ def save_checkpoint(state: Optional[dict[str, Any]]) -> None:
+ if state is not None:
+ resumable_source_manager.save_state(ButtondownResumeConfig(fanout_state=state))
+
+ results_selector: Endpoint = {"data_selector": "results", "data_selector_required": True}
+ return cast(
+ Resource,
+ build_dependent_resource(
+ endpoint_configs=BUTTONDOWN_ENDPOINTS,
+ child_endpoint=config.name,
+ fanout=config.fanout,
+ client_config=client_config,
+ path_format_values={},
+ team_id=team_id,
+ job_id=job_id,
+ db_incremental_field_last_value=None,
+ page_size_param=None,
+ resume_hook=save_checkpoint,
+ initial_paginator_state=initial_paginator_state,
+ parent_endpoint_extra=results_selector,
+ child_endpoint_extra=results_selector,
+ ),
+ )
+
+
+def buttondown_source(
+ api_key: str,
+ endpoint: str,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[ButtondownResumeConfig],
+ api_version: str = BUTTONDOWN_API_VERSION,
+ db_incremental_field_last_value: Optional[Any] = None,
+ should_use_incremental_field: bool = False,
+) -> SourceResponse:
+ config = BUTTONDOWN_ENDPOINTS[endpoint]
+ client_config = _client_config(api_key, api_version)
+
+ if config.fanout is not None:
+ resource = _fanout_resource(config, client_config, team_id, job_id, resumable_source_manager)
+ else:
+ resource = _top_level_resource(
+ config,
+ client_config,
+ team_id,
+ job_id,
+ resumable_source_manager,
+ db_incremental_field_last_value,
+ should_use_incremental_field,
+ )
+
return SourceResponse(
name=endpoint,
items=lambda: resource,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/canonical_descriptions.py
index fe09c1e79d38..a11466a38477 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/canonical_descriptions.py
@@ -6,6 +6,20 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.can
# https://docs.buttondown.com/api-introduction
CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
+ "automation_attempts": {
+ "description": "An attempt to run an automation for one subscriber, with its scheduled time, status, and any error.",
+ "docs_url": "https://docs.buttondown.com/api-subscribers-automations",
+ "columns": {
+ "actions": "The resolved actions the automation will take for this subscriber.",
+ "automation_id": "The ID of the automation that was triggered.",
+ "error": "Code for why the attempt was skipped or failed; null when it succeeded, hasn't run yet, or was skipped by hand.",
+ "execution_date": "When the automation attempt is scheduled to execute (or executed).",
+ "id": "The ID of this automation attempt.",
+ "name": "The name of the automation that was triggered.",
+ "status": "The status of the automation attempt (e.g. `pending`, `completed`, `skipped`).",
+ "subscriber_id": "The ID of the subscriber the automation ran for.",
+ },
+ },
"automations": {
"description": "An automation: a trigger, optional filters, and the actions Buttondown runs when a subscriber matches.",
"docs_url": "https://docs.buttondown.com/api-automations-list",
@@ -99,6 +113,20 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"title": "The human-readable title of the form, shown in the UI and on the hosted form page.",
},
},
+ "notes": {
+ "description": "A note attached to a subscriber, email, or other object in the newsletter.",
+ "docs_url": "https://docs.buttondown.com/api-notes-list",
+ "columns": {
+ "body": "The text content of the note.",
+ "creation_date": "The date and time at which the object was first created.",
+ "id": "A unique TypeID associated with the object.",
+ "metadata": "Additional metadata for the note.",
+ "model_id": "The UUID or TypeID of the object this note is attached to.",
+ "model_type": "The type of object this note is attached to (e.g., 'email', 'subscriber').",
+ "source": "The source of the note: `admin` if a Buttondown admin created it, otherwise `user`.",
+ "user_id": "The ID of the user who wrote the note, if any.",
+ },
+ },
"prices": {
"description": "A price for a paid subscription to the newsletter, backed by a Stripe product.",
"docs_url": "https://docs.buttondown.com/api-prices-list",
@@ -115,6 +143,36 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"suggested_amount": "The suggested amount for pay-what-you-want prices.",
},
},
+ "referrals": {
+ "description": "A subscriber who signed up through another subscriber's referral, with the full subscriber record of the referred subscriber.",
+ "docs_url": "https://docs.buttondown.com/api-subscribers-referrals",
+ "columns": {
+ "creation_date": "The date and time at which the referred subscriber was first created.",
+ "email_address": "The email address of the referred subscriber.",
+ "id": "The ID of the referred subscriber.",
+ "referral_code": "The referred subscriber's own unique referral code.",
+ "referrer_subscriber_id": "The ID of the subscriber who made the referral.",
+ "type": "The referred subscriber's lifecycle state (e.g. `regular`, `premium`, `unsubscribed`).",
+ },
+ },
+ "stripe_subscriptions": {
+ "description": "A Stripe subscription that belongs to a subscriber, covering active and ended paid subscriptions.",
+ "docs_url": "https://docs.buttondown.com/api-subscribers-stripe-subscriptions",
+ "columns": {
+ "amount": "The subscription amount in the smallest currency unit (e.g. cents). Null for tiered-pricing plans.",
+ "application_fee_percent": "The application fee percent for the subscription.",
+ "cadence": "The billing cadence (e.g. `month`, `year`).",
+ "creation_date": "The date and time at which the object was first created.",
+ "currency": "The three-letter ISO currency code (e.g. `usd`).",
+ "ending_date": "When the subscription ended, or null if still active.",
+ "product": "The name of the product which the subscriber is subscribed to.",
+ "source": "Where the subscription came from (`substack` or `buttondown`), when Buttondown can detect it.",
+ "status": "The Stripe subscription status (e.g. `active`, `canceled`, `past_due`).",
+ "subscriber_id": "The ID of the subscriber this subscription belongs to.",
+ "subscription_id": "The Stripe subscription ID (e.g. `sub_...`).",
+ "url": "A deep link to the subscription in the Stripe dashboard.",
+ },
+ },
"subscribers": {
"description": "A subscriber to the newsletter, with lifecycle state, signup attribution, and cached engagement counts.",
"docs_url": "https://docs.buttondown.com/api-subscribers-list",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/settings.py
index c73f904a3ea9..ef3a7811c0b1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/settings.py
@@ -1,10 +1,17 @@
-from dataclasses import dataclass, field
+from dataclasses import field
+from typing import Any
+from posthog.dataclasses import frozen
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ResponseAction
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SortMode
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-@dataclass
+@frozen
class ButtondownEndpointConfig:
name: str
path: str
@@ -20,6 +27,29 @@ class ButtondownEndpointConfig:
# order we cannot force stay "desc", which defers the commit to the end of a successful job.
sort_mode: SortMode = "desc"
partition_key: str | None = "creation_date"
+ # Set for per-subscriber endpoints, which are fetched once for every row of /subscribers.
+ fanout: DependentEndpointConfig | None = None
+ # Structural requirements of `FanoutEndpointLike`. Fan-out children are full refresh, and
+ # Buttondown takes no page-size param, so the fan-out passes `page_size_param=None`.
+ incremental_fields: list[Any] = field(default_factory=list)
+ default_incremental_field: str | None = None
+ page_size: int = 100
+
+
+# A subscriber deleted between the parent listing and its child fetch 404s. Skip that subscriber
+# rather than failing the whole fan-out.
+_SKIP_DELETED_SUBSCRIBER: list[ResponseAction] = [{"status_code": 404, "action": "ignore"}]
+
+
+def _per_subscriber(parent_key_name: str) -> DependentEndpointConfig:
+ return DependentEndpointConfig(
+ parent_name="subscribers",
+ resolve_param="id_or_email",
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": parent_key_name},
+ child_response_actions=_SKIP_DELETED_SUBSCRIBER,
+ )
BUTTONDOWN_ENDPOINTS: dict[str, ButtondownEndpointConfig] = {
@@ -34,6 +64,8 @@ BUTTONDOWN_ENDPOINTS: dict[str, ButtondownEndpointConfig] = {
),
"events": ButtondownEndpointConfig(name="events", path="/events", ordering="creation_date", sort_mode="asc"),
"forms": ButtondownEndpointConfig(name="forms", path="/forms", ordering="creation_date", sort_mode="asc"),
+ # /notes documents no `ordering` param and no date filter.
+ "notes": ButtondownEndpointConfig(name="notes", path="/notes"),
"prices": ButtondownEndpointConfig(name="prices", path="/prices", sort_mode="asc", partition_key=None),
# `ordering` is documented on /subscribers but its accepted values are not enumerated, and an
# unrecognized value falls back to the default `-creation_date` rather than erroring. Rather
@@ -48,6 +80,28 @@ BUTTONDOWN_ENDPOINTS: dict[str, ButtondownEndpointConfig] = {
),
"surveys": ButtondownEndpointConfig(name="surveys", path="/surveys", ordering="creation_date", sort_mode="asc"),
"tags": ButtondownEndpointConfig(name="tags", path="/tags", sort_mode="asc"),
+ # The per-subscriber endpoints take only `page`, so they are full refresh. The parent subscriber
+ # id is part of each key, because the vendor documents no table-wide uniqueness for these ids.
+ "automation_attempts": ButtondownEndpointConfig(
+ name="automation_attempts",
+ path="/subscribers/{id_or_email}/automations",
+ primary_keys=["subscriber_id", "id"],
+ partition_key="execution_date",
+ fanout=_per_subscriber("subscriber_id"),
+ ),
+ # Each row is a subscriber that the parent subscriber referred.
+ "referrals": ButtondownEndpointConfig(
+ name="referrals",
+ path="/subscribers/{id_or_email}/referrals",
+ primary_keys=["referrer_subscriber_id", "id"],
+ fanout=_per_subscriber("referrer_subscriber_id"),
+ ),
+ "stripe_subscriptions": ButtondownEndpointConfig(
+ name="stripe_subscriptions",
+ path="/subscribers/{id_or_email}/stripe-subscriptions",
+ primary_keys=["subscriber_id", "subscription_id"],
+ fanout=_per_subscriber("subscriber_id"),
+ ),
}
ENDPOINTS = tuple(BUTTONDOWN_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/tests/test_buttondown.py b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/tests/test_buttondown.py
index 07c1da5be8bc..ded2e4000236 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/tests/test_buttondown.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/buttondown/tests/test_buttondown.py
@@ -15,6 +15,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.generated_configs.buttondown import (
@@ -47,6 +48,13 @@ class TestButtondownTransport:
assert result.rows == [{"id": "a"}, {"id": "b"}]
assert result.saved_states == [ButtondownResumeConfig(next_url=page_two)]
+ def test_notes_is_a_plain_full_refresh_listing(self) -> None:
+ result = self._driver().run("notes", [_page([{"id": "note_1"}, {"id": "note_2"}])])
+
+ assert result.raised is None
+ assert result.urls[0].startswith(f"{BUTTONDOWN_BASE_URL}/notes")
+ assert [row["id"] for row in result.rows] == ["note_1", "note_2"]
+
def test_resumes_from_saved_next_url(self) -> None:
saved = f"{BUTTONDOWN_BASE_URL}/subscribers?page=7"
result = self._driver().run(
@@ -118,6 +126,78 @@ class TestButtondownTransport:
# forces ascending order. Anything else must stay on the end-of-job commit path.
assert config.sort_mode == "desc" or config.ordering == "creation_date"
+ @pytest.mark.parametrize(
+ "endpoint,child_suffix,parent_key,child_row",
+ [
+ ("stripe_subscriptions", "stripe-subscriptions", "subscriber_id", {"subscription_id": "sub_1"}),
+ ("referrals", "referrals", "referrer_subscriber_id", {"id": "sub_referred"}),
+ ("automation_attempts", "automations", "subscriber_id", {"id": "aut_att_1"}),
+ ],
+ )
+ def test_fanout_walks_every_subscriber_and_keys_rows_by_the_parent(
+ self, endpoint: str, child_suffix: str, parent_key: str, child_row: dict[str, Any]
+ ) -> None:
+ def child(subscriber: str) -> str:
+ return f"/subscribers/{subscriber}/{child_suffix}"
+
+ script = route(
+ {
+ child("sub_a"): [
+ _page([child_row], next_url=f"{BUTTONDOWN_BASE_URL}{child('sub_a')}?page=2"),
+ _page([{**child_row, "page": 2}]),
+ ],
+ # Deleted between the parent listing and its child fetch.
+ child("sub_b"): [ScriptedResponse(status=404, json={"detail": "Not found."})],
+ child("sub_c"): [_page([child_row])],
+ "/subscribers": [
+ _page([{"id": "sub_a"}], next_url=f"{BUTTONDOWN_BASE_URL}/subscribers?page=2"),
+ _page([{"id": "sub_b"}, {"id": "sub_c"}]),
+ ],
+ }
+ )
+
+ result = self._driver().run(endpoint, script)
+
+ assert result.raised is None
+ assert result.rows == [
+ {**child_row, parent_key: "sub_a"},
+ {**child_row, "page": 2, parent_key: "sub_a"},
+ {**child_row, parent_key: "sub_c"},
+ ]
+ assert result.response is not None and result.response.primary_keys is not None
+ assert parent_key in result.response.primary_keys
+
+ def test_fanout_resumes_from_the_subscriber_in_progress(self) -> None:
+ in_progress_next = f"{BUTTONDOWN_BASE_URL}/subscribers/sub_b/referrals?page=3"
+ script = route(
+ {
+ "/subscribers/sub_b/referrals": [_page([{"id": "sub_x"}])],
+ "/subscribers/sub_c/referrals": [_page([{"id": "sub_y"}])],
+ "/subscribers": [_page([{"id": "sub_a"}, {"id": "sub_b"}, {"id": "sub_c"}])],
+ }
+ )
+
+ result = self._driver().run(
+ "referrals",
+ script,
+ resume_state=ButtondownResumeConfig(
+ fanout_state={
+ "completed": ["/subscribers/sub_a/referrals"],
+ "current": "/subscribers/sub_b/referrals",
+ "child_state": {"next_url": in_progress_next},
+ }
+ ),
+ )
+
+ assert result.raised is None
+ assert result.urls[1:] == [in_progress_next, f"{BUTTONDOWN_BASE_URL}/subscribers/sub_c/referrals"]
+ assert [row["referrer_subscriber_id"] for row in result.rows] == ["sub_b", "sub_c"]
+ assert result.final_state.fanout_state["completed"] == [
+ "/subscribers/sub_a/referrals",
+ "/subscribers/sub_b/referrals",
+ "/subscribers/sub_c/referrals",
+ ]
+
def test_missing_results_key_fails_loudly(self) -> None:
result = self._driver().run("subscribers", [_page(None, drop_results=True)])