: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(cdp): coerce action IDs from BIGINT string back to number (#59452)
mendral-app[bot]b04330f2b096
diff --git a/nodejs/src/cdp/legacy-webhooks/action-manager.ts b/nodejs/src/cdp/legacy-webhooks/action-manager.tsindex 2d29fc7ea433..69c5b08b973f 100644--- a/nodejs/src/cdp/legacy-webhooks/action-manager.ts+++ b/nodejs/src/cdp/legacy-webhooks/action-manager.ts@@ -1,6 +1,7 @@import * as schedule from 'node-schedule'import { Action, Hook, RawAction, Team } from '../../types'+import { coerceActionIds } from '../../utils/coerce-action-ids'import { PostgresRouter, PostgresUse } from '../../utils/db/postgres'import { logger } from '../../utils/logger'import { PubSub } from '../../utils/pubsub'@@ -148,6 +149,8 @@ export async function fetchAllActionsGroupedByTeam(const actions: Record<Team['id'], Record<Action['id'], Action>> = {}for (const rawAction of rawActions) {+ coerceActionIds(rawAction)+if (!actions[rawAction.team_id]) {actions[rawAction.team_id] = {}}@@ -203,6 +206,8 @@ export async function fetchAction(client: PostgresRouter, id: Action['id']): Proreturn null}+ coerceActionIds(rawActions[0])+const hooks = await fetchActionRestHooks(client, id)const action: Action = { ...rawActions[0], steps: rawActions[0].steps_json ?? [], hooks }diff --git a/nodejs/src/utils/action-manager-cdp.ts b/nodejs/src/utils/action-manager-cdp.tsindex 175a0430b51e..a71c0c576da5 100644--- a/nodejs/src/utils/action-manager-cdp.ts+++ b/nodejs/src/utils/action-manager-cdp.ts@@ -1,3 +1,4 @@+import { coerceActionIds } from './coerce-action-ids'import { PostgresRouter, PostgresUse } from './db/postgres'import { LazyLoader } from './lazy-loader'@@ -72,6 +73,7 @@ export class ActionManagerCDP {// Group actions by team_idresult.rows.forEach((action) => {+ coerceActionIds(action)const teamIdStr = String(action.team_id)if (!resultRecord[teamIdStr]) {resultRecord[teamIdStr] = []diff --git a/nodejs/src/utils/coerce-action-ids.ts b/nodejs/src/utils/coerce-action-ids.tsnew file mode 100644index 000000000000..77ee8c3b2393--- /dev/null+++ b/nodejs/src/utils/coerce-action-ids.ts@@ -0,0 +1,9 @@+/**+ * posthog_action.id is BIGINT, which pg returns as string.+ * Coerce id and team_id back to number since action IDs are well within safe integer range.+ */+export function coerceActionIds<T extends { id: unknown; team_id: unknown }>(action: T): T {+ action.id = Number(action.id)+ action.team_id = Number(action.team_id)+ return action+}