: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
fix(data-imports): scope asana portfolios requests to the token's own user (#109766)
Tom Owers708ae536f659
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.pyindex 5554064378c8..3f25745eaf49 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@@ -99,7 +99,10 @@ _PARENTS: dict[FanOut, _ParentSpec] = {name="teams", param="team_gid", path="/organizations/{workspace_gid}/teams", fan_out="organization"),"portfolio": _ParentSpec(- name="portfolios", param="portfolio_gid", path="/portfolios?workspace={workspace_gid}", fan_out="workspace"+ name="portfolios",+ param="portfolio_gid",+ path="/portfolios?workspace={workspace_gid}&owner=me",+ fan_out="workspace",),}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.pyindex b05d3ed1f732..149761602404 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@@ -298,12 +298,12 @@ ASANA_ENDPOINTS: dict[str, AsanaEndpointConfig] = {path="/teams/{team_gid}/team_memberships",opt_fields=["user", "team", "is_admin", "is_guest", "is_limited_access", "resource_type"],),- # A personal access token only sees portfolios the token's own user owns; a service account sees- # every portfolio in the workspace. Nothing in the response marks which case applied.+ # Asana rejects this endpoint with a 400 for a non-service-account token unless `owner` is set;+ # "me" is the only owner this personal-access-token integration can ever request on behalf of."portfolios": AsanaEndpointConfig(name="portfolios",fan_out="workspace",- path="/portfolios?workspace={workspace_gid}",+ path="/portfolios?workspace={workspace_gid}&owner=me",opt_fields=["name","created_at",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.pyindex 75ea0eb80922..e3b9b3697c2f 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@@ -311,6 +311,25 @@ class TestFanOut:assert [(r["portfolio_gid"], r["gid"]) for r in rows] == [("PF1", "PR1"), ("PF2", "PR1")]assert not any(r for r in rows if "_portfolios_gid" in r)assert all("limit=" in url for url in sent if "/items" in url)+ # Asana 400s GET /portfolios for a non-service-account token without an explicit owner.+ assert all("owner=me" in url for url in sent if "/portfolios?" in url)++ @mock.patch(CLIENT_SESSION_PATCH)+ def test_portfolios_scope_to_the_tokens_own_user(self, MockSession) -> None:+ session = MockSession.return_value+ sent = _wire(+ session,+ [+ ("/workspaces?", _page([{"gid": "W1"}])),+ ("workspace=W1", _page([{"gid": "PF1"}])),+ ],+ )++ rows = _rows(_source("portfolios", _make_manager()))++ assert [r["gid"] for r in rows] == ["PF1"]+ # Asana 400s GET /portfolios for a non-service-account token without an explicit owner.+ assert all("owner=me" in url for url in sent if "/portfolios?" in url)@pytest.mark.parametrize("endpoint, parent_gid",