: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-warehouse): align Plain GraphQL queries with current schema (#61949)
Tom Owers59e1ced2f1b1
diff --git a/posthog/temporal/data_imports/sources/plain/plain.py b/posthog/temporal/data_imports/sources/plain/plain.pyindex 1ecb90779c20..b0aa95e34d3a 100644--- a/posthog/temporal/data_imports/sources/plain/plain.py+++ b/posthog/temporal/data_imports/sources/plain/plain.py@@ -80,10 +80,13 @@ def _flatten_node(node: dict[str, Any]) -> dict[str, Any]:flattened["customerEmail"] = customer.get("email")if "assignedToUser" in flattened and isinstance(flattened["assignedToUser"], dict):- user = flattened.pop("assignedToUser")- flattened["assignedToUserId"] = user.get("id") if user else None- flattened["assignedToUserName"] = user.get("fullName") if user else None- flattened["assignedToUserEmail"] = user.get("email") if user else None+ assignee = flattened.pop("assignedToUser")+ # Customer.assignedToUser is a UserActor wrapping a nested `user`; Thread.assignedTo (aliased+ # to assignedToUser) resolves to the assignee object directly. Handle both shapes.+ user = assignee.get("user") if isinstance(assignee.get("user"), dict) else assignee+ flattened["assignedToUserId"] = user.get("id")+ flattened["assignedToUserName"] = user.get("fullName")+ flattened["assignedToUserEmail"] = user.get("email")if "company" in flattened and isinstance(flattened["company"], dict):company = flattened.pop("company")@@ -147,9 +150,8 @@ def _flatten_timeline_entry(entry: dict[str, Any], thread_id: str) -> dict[str,flattened["fromName"] = entry_data["from"].get("name")elif entry_data.get("__typename") == "NoteEntry":flattened["noteId"] = entry_data.get("noteId")- flattened["text"] = entry_data.get("text")- elif entry_data.get("__typename") == "CustomTimelineEntry":- flattened["customEntryId"] = entry_data.get("customTimelineEntryId")+ flattened["text"] = entry_data.get("noteText")+ elif entry_data.get("__typename") == "CustomEntry":flattened["title"] = entry_data.get("title")flattened["externalId"] = entry_data.get("externalId")diff --git a/posthog/temporal/data_imports/sources/plain/queries.py b/posthog/temporal/data_imports/sources/plain/queries.pyindex d6926bebe244..1ce865061c74 100644--- a/posthog/temporal/data_imports/sources/plain/queries.py+++ b/posthog/temporal/data_imports/sources/plain/queries.py@@ -16,15 +16,17 @@ query PaginatedCustomers($first: Int!, $after: String, $filter: CustomersFilter)iso8601}assignedToUser {- id- fullName+ user {+ id+ fullName+ }}createdAt {iso8601}createdBy {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on SystemActor { systemId }@@ -33,7 +35,7 @@ query PaginatedCustomers($first: Int!, $after: String, $filter: CustomersFilter)iso8601}updatedBy {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on SystemActor { systemId }@@ -42,7 +44,7 @@ query PaginatedCustomers($first: Int!, $after: String, $filter: CustomersFilter)iso8601}markedAsSpamBy {- actorType+ actorType: __typename... on UserActor { userId }}company {@@ -80,15 +82,25 @@ query PaginatedThreads($first: Int!, $after: String, $filter: ThreadsFilter) {iso8601}statusChangedBy {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on SystemActor { systemId }}- assignedToUser {- id- fullName+ assignedToUser: assignedTo {+ __typename+ ... on User {+ id+ fullName+ }+ ... on MachineUser {+ id+ fullName+ }+ ... on System {+ id+ }}labels {id@@ -122,7 +134,7 @@ query PaginatedThreads($first: Int!, $after: String, $filter: ThreadsFilter) {iso8601}createdBy {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on SystemActor { systemId }@@ -131,7 +143,7 @@ query PaginatedThreads($first: Int!, $after: String, $filter: ThreadsFilter) {iso8601}updatedBy {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on SystemActor { systemId }@@ -156,7 +168,7 @@ query ThreadTimelineEntries($threadId: ID!, $first: Int!, $after: String) {iso8601}actor {- actorType+ actorType: __typename... on UserActor { userId }... on MachineUserActor { machineUserId }... on CustomerActor { customerId }@@ -183,10 +195,9 @@ query ThreadTimelineEntries($threadId: ID!, $first: Int!, $after: String) {}... on NoteEntry {noteId- text+ noteText: text}- ... on CustomTimelineEntry {- customTimelineEntryId+ ... on CustomEntry {titleexternalId}diff --git a/posthog/temporal/data_imports/sources/plain/tests/test_plain.py b/posthog/temporal/data_imports/sources/plain/tests/test_plain.pyindex 5d51c71525b4..e70dffc2e28b 100644--- a/posthog/temporal/data_imports/sources/plain/tests/test_plain.py+++ b/posthog/temporal/data_imports/sources/plain/tests/test_plain.py@@ -45,8 +45,8 @@ class TestFlattenNode:"email": {"email": "[email protected]", "isVerified": True},"createdAt": {"iso8601": "2024-01-01T00:00:00Z"},"updatedAt": {"iso8601": "2024-02-01T00:00:00Z"},- "assignedToUser": {"id": "u_1", "fullName": "Bob", "email": "[email protected]"},- "createdBy": {"actorType": "user", "userId": "u_2"},+ "assignedToUser": {"user": {"id": "u_1", "fullName": "Bob", "email": "[email protected]"}},+ "createdBy": {"actorType": "UserActor", "userId": "u_2"},"company": {"id": "co_1", "name": "Acme"},}result = _flatten_node(node)@@ -58,11 +58,21 @@ class TestFlattenNode:assert result["updatedAt"] == "2024-02-01T00:00:00Z"assert result["assignedToUserId"] == "u_1"assert result["assignedToUserName"] == "Bob"- assert result["createdByType"] == "user"+ assert result["createdByType"] == "UserActor"assert result["createdById"] == "u_2"assert result["companyId"] == "co_1"assert result["companyName"] == "Acme"+ def test_flattens_thread_assignee_resolved_directly(self):+ # Thread.assignedTo (aliased to assignedToUser) resolves to the assignee object directly,+ # unlike Customer.assignedToUser which wraps a nested `user`.+ node = {"id": "t_1", "assignedToUser": {"id": "u_1", "fullName": "Bob", "email": "[email protected]"}}+ result = _flatten_node(node)++ assert result["assignedToUserId"] == "u_1"+ assert result["assignedToUserName"] == "Bob"+ assert result["assignedToUserEmail"] == "[email protected]"+def test_flattens_thread_with_labels_and_message_info(self):node = {"id": "t_1",@@ -138,7 +148,7 @@ class TestFlattenTimelineEntry:"id": "te_3","timestamp": {"iso8601": "2024-01-01T00:00:00Z"},"actor": {"actorType": "user", "userId": "u_1"},- "entry": {"__typename": "NoteEntry", "noteId": "note_1", "text": "internal"},+ "entry": {"__typename": "NoteEntry", "noteId": "note_1", "noteText": "internal"},}result = _flatten_timeline_entry(entry, thread_id="t_1")@@ -146,6 +156,19 @@ class TestFlattenTimelineEntry:assert result["noteId"] == "note_1"assert result["text"] == "internal"+ def test_custom_entry(self):+ entry = {+ "id": "te_4",+ "timestamp": {"iso8601": "2024-01-01T00:00:00Z"},+ "actor": {"actorType": "user", "userId": "u_1"},+ "entry": {"__typename": "CustomEntry", "title": "Order placed", "externalId": "ext_1"},+ }+ result = _flatten_timeline_entry(entry, thread_id="t_1")++ assert result["entryType"] == "CustomEntry"+ assert result["title"] == "Order placed"+ assert result["externalId"] == "ext_1"+class TestPlainSourcePipeline:def test_unknown_endpoint_raises(self):