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(bugherd): sync task comments, board columns, archived and feedback tasks (#100158)

Tom Owerse12051e87283
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 0bfcf9c69695..ecbfa4034ca7 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
@@ -1010,14 +1010,14 @@ Note: Fetched the v3 OpenAPI spec (linked from docs.browser-use.com/llms.txt); t
## Bugherd — gaps
-Today (4): `Organization`, `Projects`, `Tasks`, `Users`
+Today (8): `ArchivedTasks`, `Columns`, `FeedbackTasks`, `Organization`, `Projects`, `TaskComments`, `Tasks`, `Users`
Diffed against: <https://docs.bugherd.com/api/openapi.yaml>
-- [ ] `GET /api_v2/projects/{project_id}/tasks/{task_id}/comments.json` — task discussion thread — the main activity signal on a bug, and the only per-task event grain available (high)
-- [ ] `GET /api_v2/projects/{project_id}/columns.json` — lookup resolving the board column/status a task sits in (high)
-- [ ] `GET /api_v2/projects/{project_id}/tasks/archive.json` — archived (closed-out) tasks live behind a separate endpoint, so completed work is entirely missing from the tasks table (high)
-- [ ] `GET /api_v2/projects/{project_id}/tasks/feedback.json` — the unsorted feedback inbox — tasks not yet promoted to the board (medium)
+- [x] `GET /api_v2/projects/{project_id}/tasks/{task_id}/comments.json` — task discussion thread — the main activity signal on a bug, and the only per-task event grain available (high)
+- [x] `GET /api_v2/projects/{project_id}/columns.json` — lookup resolving the board column/status a task sits in (high)
+- [x] `GET /api_v2/projects/{project_id}/tasks/archive.json` — archived (closed-out) tasks live behind a separate endpoint, so completed work is entirely missing from the tasks table (high)
+- [x] `GET /api_v2/projects/{project_id}/tasks/feedback.json` — the unsorted feedback inbox — tasks not yet promoted to the board (medium)
- [ ] `GET /api_v2/projects/{project_id}/tasks/{task_id}/attachments.json` — screenshots and files attached to a task, joinable to tasks (medium)
- [ ] `GET /api_v2/users/{user_id}/projects.json` — membership join between users and projects; neither existing table carries the relationship (medium)
- [ ] `GET /api_v2/users/members.json and GET /api_v2/users/guests.json` — splits the flat users list into members vs guests, which is how BugHerd seats are licensed (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/bugherd.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/bugherd.py
index 874ddd66703f..a7e029d56e2f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/bugherd.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/bugherd.py
@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
rest_api_resource,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_chained_resource,
build_dependent_resource,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
@@ -125,6 +126,80 @@ def _resource(
}
+def _chained_fanout_resource(
+ config: BugherdEndpointConfig,
+ client_config: ClientConfig,
+ team_id: int,
+ job_id: str,
+) -> Iterable[Any]:
+ """Build a Projects -> Tasks -> child resource chain and return the child."""
+ chained = config.chained_fanout
+ assert chained is not None
+ middle_config = BUGHERD_ENDPOINTS[chained.parent_name]
+ root_fanout = middle_config.fanout
+ if root_fanout is None:
+ raise ValueError(f"'{chained.parent_name}' does not fan out from a top-level endpoint")
+ root_config = BUGHERD_ENDPOINTS[root_fanout.parent_name]
+
+ root_resource: EndpointResource = {
+ "name": root_config.name,
+ "table_name": root_config.name,
+ "write_disposition": "replace",
+ "endpoint": {
+ "path": root_config.path,
+ "data_selector": root_config.data_selector,
+ "paginator": _list_paginator(root_config),
+ },
+ "table_format": "delta",
+ }
+ middle_resource: EndpointResource = {
+ "name": middle_config.name,
+ "table_name": middle_config.name,
+ "write_disposition": "replace",
+ "endpoint": {
+ "path": middle_config.path,
+ "data_selector": middle_config.data_selector,
+ "paginator": _list_paginator(middle_config),
+ "params": {
+ root_fanout.resolve_param: {
+ "type": "resolve",
+ "resource": root_config.name,
+ "field": root_fanout.resolve_field,
+ },
+ },
+ },
+ "table_format": "delta",
+ }
+ child_resource: EndpointResource = {
+ "name": config.name,
+ "table_name": config.name,
+ "write_disposition": "replace",
+ "include_from_parent": chained.include_from_parent,
+ "endpoint": {
+ "path": config.path,
+ "data_selector": config.data_selector,
+ "paginator": _list_paginator(config),
+ "params": {
+ param: {"type": "resolve", "resource": middle_config.name, "field": field_name}
+ for param, field_name in chained.resolve_fields.items()
+ },
+ # A task removed between its Tasks page and this fetch must not sink the run.
+ "response_actions": [{"status_code": 404, "action": "ignore"}],
+ },
+ "table_format": "delta",
+ }
+
+ return build_chained_resource(
+ resources=[root_resource, middle_resource, child_resource],
+ child_name=config.name,
+ parent_name=middle_config.name,
+ parent_field_renames=chained.parent_field_renames,
+ client_config=client_config,
+ team_id=team_id,
+ job_id=job_id,
+ )
+
+
def _make_source_response(config: BugherdEndpointConfig, items_fn: Callable[[], Iterable[Any]]) -> SourceResponse:
primary_keys = config.primary_key if isinstance(config.primary_key, list) else [config.primary_key]
return SourceResponse(
@@ -163,6 +238,9 @@ def bugherd_source(
if state and state.get("page") is not None:
resumable_source_manager.save_state(BugherdResumeConfig(page=int(state["page"])))
+ if config.chained_fanout is not None:
+ return _make_source_response(config, lambda: _chained_fanout_resource(config, client_config, team_id, job_id))
+
if config.fanout is not None:
parent_config = BUGHERD_ENDPOINTS[config.fanout.parent_name]
resource = cast(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/canonical_descriptions.py
index 4257bd6d1f40..5dbbfcef369e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/canonical_descriptions.py
@@ -4,6 +4,35 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.can
_API_DOCS_URL = "https://docs.bugherd.com/api"
+# The archived and feedback task lists return the same Task object as the board list.
+_TASK_COLUMNS = {
+ "id": "Globally unique task ID.",
+ "local_task_id": "Project-scoped task number, shown as #number in the BugHerd UI.",
+ "project_id": "ID of the project the task belongs to.",
+ "created_at": "Timestamp when the task was created.",
+ "updated_at": "Timestamp when the task was last updated.",
+ "closed_at": "Timestamp when the task was closed, if applicable.",
+ "deleted_at": "Timestamp when the task was deleted, if applicable.",
+ "title": "The task's title.",
+ "description": "The task's description.",
+ "status": "Status column name the task is in (e.g. backlog, todo, doing, done, closed, or a custom column name).",
+ "status_id": "Numeric status/column ID. 0=backlog, 1=todo, 2=doing, 4=done, 5=closed; values above 5 indicate a custom column.",
+ "priority": "Priority label (not set, critical, important, normal, minor).",
+ "priority_id": "Numeric priority ID corresponding to `priority`.",
+ "site": "The website the task was logged on.",
+ "url": "The specific page path the task was logged on.",
+ "tag_names": "Tags applied to the task.",
+ "external_id": "Optional external reference ID set via the API (e.g. a linked issue key).",
+ "requester_email": "Email address of the person who reported the task.",
+ "requester_id": "User ID of the person who reported the task, if they are a known user.",
+ "assigned_to_id": "User ID the task is assigned to, if any.",
+ "assignee_ids": "User IDs assigned to the task.",
+ "due_at": "Timestamp the task is due, if set.",
+ "column_id": "ID of the kanban column the task currently sits in.",
+ "secret_link": "Unguessable public URL for the task; no login required.",
+ "admin_link": "Task board URL for the task; login required.",
+}
+
CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"Organization": {
"description": "Top-level details about your BugHerd organization.",
@@ -45,32 +74,42 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"Tasks": {
"description": "Bug reports and feedback items ('tasks') logged against a project's kanban board.",
"docs_url": _API_DOCS_URL,
+ "columns": _TASK_COLUMNS,
+ },
+ "ArchivedTasks": {
+ "description": "Tasks that have been closed or archived in a project, and so no longer appear on the active taskboard.",
+ "docs_url": _API_DOCS_URL,
+ "columns": _TASK_COLUMNS,
+ },
+ "FeedbackTasks": {
+ "description": "Tasks sitting in a project's backlog (feedback) column, not yet triaged onto the board.",
+ "docs_url": _API_DOCS_URL,
+ "columns": _TASK_COLUMNS,
+ },
+ "Columns": {
+ "description": "Kanban columns on a project's board, including the built-in backlog, todo, doing and done columns and any custom ones.",
+ "docs_url": _API_DOCS_URL,
+ "columns": {
+ "id": "Identifier for the column, unique within its project.",
+ "name": "The column's display name.",
+ "project_id": "ID of the project the column belongs to.",
+ "position": "Display order of the column on the board, 0-indexed.",
+ "tasks_count": "Number of tasks in the column. BugHerd documents this as unreliable -- it can return incorrect or negative values.",
+ "created_at": "Timestamp when the column was created.",
+ "updated_at": "Timestamp when the column was last updated.",
+ },
+ },
+ "TaskComments": {
+ "description": "Comments posted on a task, forming its discussion thread.",
+ "docs_url": _API_DOCS_URL,
"columns": {
- "id": "Globally unique task ID.",
- "local_task_id": "Project-scoped task number, shown as #number in the BugHerd UI.",
- "project_id": "ID of the project the task belongs to.",
- "created_at": "Timestamp when the task was created.",
- "updated_at": "Timestamp when the task was last updated.",
- "closed_at": "Timestamp when the task was closed, if applicable.",
- "deleted_at": "Timestamp when the task was deleted, if applicable.",
- "title": "The task's title.",
- "description": "The task's description.",
- "status": "Status column name the task is in (e.g. backlog, todo, doing, done, closed, or a custom column name).",
- "status_id": "Numeric status/column ID. 0=backlog, 1=todo, 2=doing, 4=done, 5=closed; values above 5 indicate a custom column.",
- "priority": "Priority label (not set, critical, important, normal, minor).",
- "priority_id": "Numeric priority ID corresponding to `priority`.",
- "site": "The website the task was logged on.",
- "url": "The specific page path the task was logged on.",
- "tag_names": "Tags applied to the task.",
- "external_id": "Optional external reference ID set via the API (e.g. a linked issue key).",
- "requester_email": "Email address of the person who reported the task.",
- "requester_id": "User ID of the person who reported the task, if they are a known user.",
- "assigned_to_id": "User ID the task is assigned to, if any.",
- "assignee_ids": "User IDs assigned to the task.",
- "due_at": "Timestamp the task is due, if set.",
- "column_id": "ID of the kanban column the task currently sits in.",
- "secret_link": "Unguessable public URL for the task; no login required.",
- "admin_link": "Task board URL for the task; login required.",
+ "id": "Identifier for the comment, unique within its task.",
+ "task_id": "ID of the task the comment was posted on.",
+ "project_id": "ID of the project the commented-on task belongs to.",
+ "text": "Body of the comment.",
+ "created_at": "Timestamp when the comment was posted.",
+ "user_id": "ID of the user who posted the comment.",
+ "is_private": "Whether the comment is visible only to team members, not guests/clients.",
},
},
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/settings.py
index d42ec7555297..296a3517763c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/settings.py
@@ -9,7 +9,6 @@ from products.warehouse_sources.backend.types import IncrementalField
BUGHERD_BASE_URL = "https://www.bugherd.com"
-# Tasks is the only endpoint that fans out from Projects today.
PROJECT_ID_FANOUT = DependentEndpointConfig(
parent_name="Projects",
resolve_param="project_id",
@@ -19,7 +18,32 @@ PROJECT_ID_FANOUT = DependentEndpointConfig(
)
-@dataclass
+@dataclass(frozen=True)
+class BugherdChainedFanoutConfig:
+ """A second-level fan-out whose child path binds several ids from one parent row.
+
+ `build_dependent_resource` resolves a single path param from a single parent, so it
+ cannot express `/projects/{project_id}/tasks/{task_id}/comments.json`, where both ids
+ come from the same Tasks row. `parent_name` names an endpoint that is itself a fan-out
+ child, so the built resource chain is Projects -> Tasks -> child.
+ """
+
+ parent_name: str
+ # Child path param -> the field on the parent row it binds to.
+ resolve_fields: dict[str, str]
+ include_from_parent: list[str]
+ parent_field_renames: dict[str, str]
+
+
+TASK_COMMENTS_FANOUT = BugherdChainedFanoutConfig(
+ parent_name="Tasks",
+ resolve_fields={"project_id": "project_id", "task_id": "id"},
+ include_from_parent=["id", "project_id"],
+ parent_field_renames={"id": "task_id", "project_id": "project_id"},
+)
+
+
+@dataclass(frozen=True)
class BugherdEndpointConfig:
name: str
path: str
@@ -27,8 +51,8 @@ class BugherdEndpointConfig:
primary_key: str | list[str] = "id"
# BugHerd list endpoints return a fixed ~100 rows/page with no client-configurable
# size param, so `page_size` is unused (kept only to satisfy the fan-out helper's
- # structural typing) and `paginated=False` is only for the single-object Organization
- # endpoint.
+ # structural typing). `paginated=False` is for endpoints that return their whole
+ # collection in one response and document no `page` param.
page_size: int = 100
paginated: bool = True
partition_key: str | None = None
@@ -39,6 +63,7 @@ class BugherdEndpointConfig:
incremental_query_params: dict[str, str] = field(default_factory=dict)
sort_mode: Literal["asc", "desc"] = "asc"
fanout: DependentEndpointConfig | None = None
+ chained_fanout: BugherdChainedFanoutConfig | None = None
BUGHERD_ENDPOINTS: dict[str, BugherdEndpointConfig] = {
@@ -85,6 +110,53 @@ BUGHERD_ENDPOINTS: dict[str, BugherdEndpointConfig] = {
# batching, not a corrupted watermark.
fanout=PROJECT_ID_FANOUT,
),
+ # Closed-out tasks live behind their own endpoint and never appear in `Tasks`, so
+ # without this table completed work is missing entirely. It takes no `updated_since`
+ # or `created_since` filter, hence full refresh.
+ "ArchivedTasks": BugherdEndpointConfig(
+ name="ArchivedTasks",
+ path="/api_v2/projects/{project_id}/tasks/archive.json",
+ data_selector="tasks",
+ partition_key="created_at",
+ fanout=PROJECT_ID_FANOUT,
+ ),
+ # The unsorted feedback inbox -- backlog tasks not yet promoted to the board. Also
+ # takes no timestamp filter.
+ "FeedbackTasks": BugherdEndpointConfig(
+ name="FeedbackTasks",
+ path="/api_v2/projects/{project_id}/tasks/feedback.json",
+ data_selector="tasks",
+ partition_key="created_at",
+ fanout=PROJECT_ID_FANOUT,
+ ),
+ # Built-in and custom kanban columns, which resolve a task's `column_id`/`status_id`
+ # to a board position. A project has a handful of columns and the endpoint documents
+ # no `page` param, so it returns the whole collection in one response.
+ "Columns": BugherdEndpointConfig(
+ name="Columns",
+ path="/api_v2/projects/{project_id}/columns.json",
+ data_selector="columns",
+ # Built-in columns (backlog, todo, doing, done) exist in every project and BugHerd
+ # documents no global uniqueness for column IDs, so scope the key by project.
+ primary_key=["project_id", "id"],
+ paginated=False,
+ fanout=PROJECT_ID_FANOUT,
+ ),
+ # The task discussion thread, and the only per-task event grain BugHerd exposes. The
+ # endpoint carries no timestamp filter, and bounding the Tasks walk by `updated_since`
+ # instead would assume a new comment bumps its task's `updated_at` -- which BugHerd
+ # does not document (it fires `comment` and `task_update` as separate webhook events).
+ # So full refresh, which re-walks every task each sync.
+ "TaskComments": BugherdEndpointConfig(
+ name="TaskComments",
+ path="/api_v2/projects/{project_id}/tasks/{task_id}/comments.json",
+ data_selector="comments",
+ # The delete route addresses a comment by project and task as well as comment ID,
+ # so treat the ID as task-scoped rather than global.
+ primary_key=["task_id", "id"],
+ partition_key="created_at",
+ chained_fanout=TASK_COMMENTS_FANOUT,
+ ),
}
ENDPOINTS = tuple(BUGHERD_ENDPOINTS)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/source.py
index 547c95a6f65a..f75a7ed966bc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/source.py
@@ -105,7 +105,7 @@ class BugherdSource(ResumableSource[BugherdSourceConfig, BugherdResumeConfig]):
name=SchemaExternalDataSourceType.BUGHERD,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="BugHerd",
- caption="""Enter your BugHerd API key to sync your organization, projects, tasks, and users into the PostHog Data warehouse.
+ caption="""Enter your BugHerd API key to sync your organization, projects, tasks, task comments, board columns, and users into the PostHog Data warehouse.
Find your API key in BugHerd under **Settings > General Settings** (organization owner/admin access is required).""",
docsUrl="https://posthog.com/docs/cdp/sources/bugherd",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/tests/test_bugherd.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/tests/test_bugherd.py
index 1422210edf18..afd1c74ae197 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/tests/test_bugherd.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bugherd/tests/test_bugherd.py
@@ -13,7 +13,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.bugherd.bu
bugherd_source,
validate_credentials,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.bugherd.settings import BUGHERD_ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.bugherd.settings import (
+ BUGHERD_BASE_URL,
+ BUGHERD_ENDPOINTS,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
PageNumberPaginator,
SinglePagePaginator,
@@ -332,3 +335,118 @@ class TestBugherdFanout:
kwargs["resume_hook"]({"page": 4})
manager.save_state.assert_called_once_with(BugherdResumeConfig(page=4))
+
+
+class TestBugherdChainedFanout:
+ def _comments_rows(self, requests_mock: Any) -> list[dict]:
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = False
+
+ resp = bugherd_source(
+ api_key="key", endpoint="TaskComments", team_id=1, job_id="job-1", resumable_source_manager=manager
+ )
+
+ return [row for page in cast(Any, resp.items()) for row in page]
+
+ def test_walks_projects_then_tasks_then_comments(self, requests_mock: Any) -> None:
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects.json",
+ [{"json": {"projects": [{"id": 1000}]}}, {"json": {"projects": []}}],
+ )
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects/1000/tasks.json",
+ [{"json": {"tasks": [{"id": 98765, "project_id": 1000}]}}, {"json": {"tasks": []}}],
+ )
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects/1000/tasks/98765/comments.json",
+ [{"json": {"comments": [{"id": 8801, "text": "reproduced"}]}}, {"json": {"comments": []}}],
+ )
+
+ rows = self._comments_rows(requests_mock)
+
+ assert rows == [{"id": 8801, "text": "reproduced", "task_id": 98765, "project_id": 1000}]
+
+ def test_skips_a_task_that_disappeared_between_pages(self, requests_mock: Any) -> None:
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects.json",
+ [{"json": {"projects": [{"id": 1000}]}}, {"json": {"projects": []}}],
+ )
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects/1000/tasks.json",
+ [
+ {"json": {"tasks": [{"id": 1, "project_id": 1000}, {"id": 2, "project_id": 1000}]}},
+ {"json": {"tasks": []}},
+ ],
+ )
+ requests_mock.get(f"{BUGHERD_BASE_URL}/api_v2/projects/1000/tasks/1/comments.json", status_code=404, json={})
+ requests_mock.get(
+ f"{BUGHERD_BASE_URL}/api_v2/projects/1000/tasks/2/comments.json",
+ [{"json": {"comments": [{"id": 9, "text": "still here"}]}}, {"json": {"comments": []}}],
+ )
+
+ rows = self._comments_rows(requests_mock)
+
+ assert [row["id"] for row in rows] == [9]
+
+ def test_composite_primary_key(self) -> None:
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = False
+
+ resp = bugherd_source(
+ api_key="key", endpoint="TaskComments", team_id=1, job_id="job-1", resumable_source_manager=manager
+ )
+
+ assert resp.primary_keys == ["task_id", "id"]
+ assert resp.partition_keys == ["created_at"]
+
+
+class TestBugherdProjectFanoutEndpoints:
+ @parameterized.expand(
+ [
+ ("ArchivedTasks", "/api_v2/projects/{project_id}/tasks/archive.json"),
+ ("FeedbackTasks", "/api_v2/projects/{project_id}/tasks/feedback.json"),
+ ]
+ )
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.bugherd.bugherd.build_dependent_resource")
+ def test_task_list_stays_full_refresh_when_incremental_is_requested(
+ self, endpoint: str, path: str, mock_build
+ ) -> None:
+ # These endpoints take no `updated_since`/`created_since`, so they declare no
+ # incremental fields and no query-param mapping — asking for incremental anyway
+ # must not reach the window factory, which would KeyError.
+ mock_build.return_value = iter([])
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = False
+
+ resp = bugherd_source(
+ api_key="key",
+ endpoint=endpoint,
+ team_id=1,
+ job_id="job-1",
+ resumable_source_manager=manager,
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=datetime(2024, 1, 1, tzinfo=UTC),
+ incremental_field="updated_at",
+ )
+
+ assert resp.primary_keys == ["id"]
+ _, kwargs = mock_build.call_args
+ assert BUGHERD_ENDPOINTS[endpoint].path == path
+ assert BUGHERD_ENDPOINTS[endpoint].incremental_fields == []
+
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.bugherd.bugherd.build_dependent_resource")
+ def test_columns_child_is_not_paginated(self, mock_build) -> None:
+ mock_build.return_value = iter([])
+ manager = MagicMock(spec=ResumableSourceManager)
+ manager.can_resume.return_value = False
+
+ resp = bugherd_source(
+ api_key="key", endpoint="Columns", team_id=1, job_id="job-1", resumable_source_manager=manager
+ )
+
+ _, kwargs = mock_build.call_args
+ # Columns returns its whole collection in one response; a page paginator would
+ # re-request page 2 forever on an API that ignores `page`.
+ assert isinstance(kwargs["child_endpoint_extra"]["paginator"], SinglePagePaginator)
+ assert isinstance(kwargs["parent_endpoint_extra"]["paginator"], PageNumberPaginator)
+ assert resp.primary_keys == ["project_id", "id"]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py
index c71775664514..526f7fd46dde 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/fanout.py
@@ -1,4 +1,4 @@
-from collections.abc import Callable, Iterable, Mapping
+from collections.abc import Callable, Iterable, Mapping, Sequence
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Literal, Protocol
@@ -293,6 +293,36 @@ def build_dependent_resource(
return child
+def build_chained_resource(
+ *,
+ resources: Sequence[EndpointResource],
+ child_name: str,
+ parent_name: str,
+ parent_field_renames: dict[str, str],
+ client_config: ClientConfig,
+ team_id: int,
+ job_id: str,
+) -> Iterable[Any]:
+ """Build a multi-level fan-out from a caller-assembled resource list and return the child.
+
+ `build_dependent_resource` covers one hop bound by one resolved param. A child whose path
+ binds several ids from the same parent row, or whose parent is itself a fan-out child,
+ needs its own resource list, which the caller assembles and passes here.
+
+ Such a chain carries no resume state: `create_resources` withholds the hook from every
+ resource once more than one is dependent, because one hook consumed at two levels would
+ corrupt the saved page.
+ """
+ config: RESTAPIConfig = {
+ "client": client_config,
+ "resource_defaults": {},
+ "resources": list(resources),
+ }
+ built = rest_api_resources(config, team_id, job_id, None)
+ child = next(r for r in built if getattr(r, "name", None) == child_name)
+ return child.add_map(rename_parent_fields(parent_name, parent_field_renames))
+
+
def _not_newer_than(field: str, snapshot_at: datetime) -> Callable[[dict[str, Any]], bool]:
"""Keep rows the parent snapshot could already account for.