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.

fix(data-warehouse): scope asana /users requests to a workspace (#103660)

Tom Owers1e457d834d83
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/asana.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/asana.py
index 63d435a81142..5554064378c8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/asana.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/asana.py
@@ -93,7 +93,8 @@ _PARENTS: dict[FanOut, _ParentSpec] = {
),
"task": _ParentSpec(name="tasks", param="task_gid", path="/tasks?project={project_gid}", fan_out="project"),
"goal": _ParentSpec(name="goals", param="goal_gid", path="/goals?workspace={workspace_gid}", fan_out="workspace"),
- "user": _ParentSpec(name="users", param="user_gid", path="/users"),
+ # Scoped per workspace because Asana rejects an unscoped /users for a multi-workspace token.
+ "user": _ParentSpec(name="users", param="user_gid", path="/users?workspace={workspace_gid}", fan_out="workspace"),
"team": _ParentSpec(
name="teams", param="team_gid", path="/organizations/{workspace_gid}/teams", fan_out="organization"
),
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/settings.py
index 60cc1d0bb2dc..b05d3ed1f732 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/settings.py
@@ -70,10 +70,13 @@ ASANA_ENDPOINTS: dict[str, AsanaEndpointConfig] = {
path="/workspaces",
opt_fields=["name", "email_domains", "is_organization", "resource_type"],
),
+ # Asana rejects an unscoped /users when the token's user belongs to more than one workspace, so
+ # the walk is scoped per workspace. A user in several workspaces comes back once per workspace;
+ # the `gid` primary key collapses those repeats into one row.
"users": AsanaEndpointConfig(
name="users",
- fan_out="none",
- path="/users",
+ fan_out="workspace",
+ path="/users?workspace={workspace_gid}",
opt_fields=["name", "email", "photo", "workspaces", "resource_type"],
),
"projects": AsanaEndpointConfig(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/tests/test_asana.py b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/tests/test_asana.py
index f8f5adef6d95..75ea0eb80922 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/asana/tests/test_asana.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/asana/tests/test_asana.py
@@ -220,21 +220,31 @@ class TestFanOut:
# The tasks level is fetched compact — story opt_fields must not leak onto the parent walk.
assert not any("opt_fields" in url for url in sent if "project=P1" in url)
+ @pytest.mark.parametrize(
+ "endpoint, child_routes, expected_gids",
+ [
+ ("users", [], ["U1", "U2"]),
+ ("time_tracking_entries", [("user=U1", [{"gid": "e1"}]), ("user=U2", [])], ["e1"]),
+ ],
+ )
@mock.patch(CLIENT_SESSION_PATCH)
- def test_user_fan_out_filters_time_tracking_entries_per_user(self, MockSession) -> None:
+ def test_users_are_walked_per_workspace(self, MockSession, endpoint, child_routes, expected_gids) -> None:
session = MockSession.return_value
sent = _wire(
session,
[
+ ("/workspaces?", _page([{"gid": "W1"}])),
("/users", _page([{"gid": "U1"}, {"gid": "U2"}])),
- ("user=U1", _page([{"gid": "e1"}])),
- ("user=U2", _page([])),
+ *[(substr, _page(items)) for substr, items in child_routes],
],
)
- rows = _rows(_source("time_tracking_entries", _make_manager()))
+ rows = _rows(_source(endpoint, _make_manager()))
- assert [r["gid"] for r in rows] == ["e1"]
+ assert [r["gid"] for r in rows] == expected_gids
+ # Asana rejects an unscoped /users once the token can see more than one workspace.
+ user_urls = [url for url in sent if "/users" in url]
+ assert user_urls and all("workspace=W1" in url for url in user_urls)
# Every entry request is scoped to a user; an unfiltered request would be rejected.
assert all("user=" in url for url in sent if "/time_tracking_entries" in url)