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(integrations): coerce integration id to number in IntegrationChoice lookup (#61697)

Javier Bahamondes3930535a16b1
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx
index 7f95471ceb68..0584fc748000 100644
--- a/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx
+++ b/frontend/src/lib/components/CyclotronJob/integrations/IntegrationChoice.tsx
@@ -10,6 +10,7 @@ import { IntegrationView } from 'lib/integrations/IntegrationView'
import { getIntegrationNameFromKind } from 'lib/integrations/utils'
import { urls } from 'scenes/urls'
+import { findIntegrationByFormValue, matchesIntegrationIdValue } from './integrationLookup'
import { getAllRegisteredIntegrationSetups, getIntegrationSetup } from './integrationSetupRegistry'
// Side-effect import: register all integration setups
@@ -38,7 +39,7 @@ export function IntegrationChoice({
const kind = integration
const integrationsOfKind = integrations?.filter((x) => x.kind === kind)
- const integrationKind = integrationsOfKind?.find((integration) => integration.id === value)
+ const integrationKind = findIntegrationByFormValue(integrationsOfKind, value)
// The stored value points to an integration that's no longer available (deleted, or
// re-installed under a new ID). We deliberately do NOT auto-substitute here — that
@@ -124,7 +125,7 @@ export function IntegrationChoice({
/>
),
onClick: () => onChange?.(integ.id),
- active: integ.id === value,
+ active: matchesIntegrationIdValue(integ.id, value),
label: integ.display_name,
})) || []),
],
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.test.ts b/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.test.ts
new file mode 100644
index 000000000000..071f68d53406
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.test.ts
@@ -0,0 +1,77 @@
+import { IntegrationType } from '~/types'
+
+import { findIntegrationByFormValue, matchesIntegrationIdValue } from './integrationLookup'
+
+const integration = (overrides: Partial<IntegrationType> = {}): IntegrationType => ({
+ id: 7,
+ kind: 'google-ads',
+ icon_url: '',
+ config: {},
+ created_at: '2026-06-04T16:44:10Z',
+ created_by: null,
+ errors: '',
+ display_name: '[email protected]',
+ ...overrides,
+})
+
+describe('matchesIntegrationIdValue', () => {
+ it('matches when value is the same number', () => {
+ expect(matchesIntegrationIdValue(7, 7)).toBe(true)
+ })
+
+ it('matches when value is a stringified number — regression', () => {
+ // Reproduces the bug: integration IDs hydrated from a stored source's
+ // JSONB job_inputs arrive as strings even though the API returns numbers.
+ expect(matchesIntegrationIdValue(7, '7')).toBe(true)
+ })
+
+ it('does not match when ids differ', () => {
+ expect(matchesIntegrationIdValue(7, 8)).toBe(false)
+ expect(matchesIntegrationIdValue(7, '8')).toBe(false)
+ })
+
+ it.each([
+ ['undefined', undefined],
+ ['null', null],
+ ['empty string', ''],
+ ])('returns false for %s value (no selection)', (_label, value) => {
+ expect(matchesIntegrationIdValue(7, value)).toBe(false)
+ })
+
+ it.each([
+ ['non-numeric string', 'seven'],
+ ['whitespace only', ' '],
+ ['NaN-producing', 'not-a-number'],
+ ])('returns false for non-numeric value (%s)', (_label, value) => {
+ expect(matchesIntegrationIdValue(7, value)).toBe(false)
+ })
+})
+
+describe('findIntegrationByFormValue', () => {
+ const integrations = [integration({ id: 6 }), integration({ id: 7 })]
+
+ it('finds the integration when value is a number', () => {
+ expect(findIntegrationByFormValue(integrations, 7)?.id).toBe(7)
+ })
+
+ it('finds the integration when value is a stringified number — regression', () => {
+ // The exact code path that was producing the "no longer available" banner
+ // for every loaded source on the Configuration tab.
+ expect(findIntegrationByFormValue(integrations, '7')?.id).toBe(7)
+ })
+
+ it('returns undefined when no integration matches', () => {
+ expect(findIntegrationByFormValue(integrations, 99)).toBeUndefined()
+ expect(findIntegrationByFormValue(integrations, '99')).toBeUndefined()
+ })
+
+ it.each([
+ ['null integrations list (still loading)', null, 7],
+ ['undefined integrations list', undefined, 7],
+ ['undefined value', integrations, undefined],
+ ['null value', integrations, null],
+ ['empty-string value', integrations, ''],
+ ])('returns undefined for %s', (_label, list, value) => {
+ expect(findIntegrationByFormValue(list as IntegrationType[] | null | undefined, value as any)).toBeUndefined()
+ })
+})
diff --git a/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.ts b/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.ts
new file mode 100644
index 000000000000..317610f05438
--- /dev/null
+++ b/frontend/src/lib/components/CyclotronJob/integrations/integrationLookup.ts
@@ -0,0 +1,45 @@
+import { IntegrationType } from '~/types'
+
+export type IntegrationIdValue = IntegrationType['id'] | string | null | undefined
+
+/**
+ * Whether a stored form value points to a given integration.
+ *
+ * `integration.id` is a JSON number from the API, but `value` can arrive as a
+ * string when the form is hydrated from a source's stored `job_inputs` (Postgres
+ * JSONB preserves whatever was originally written, and some source flows end up
+ * persisting the OAuth integration ID as a string). Strict equality on a number
+ * vs a string silently misses — `7 === "7"` is `false` in JS — which would
+ * otherwise trip the "previously selected ... is no longer available" banner
+ * and de-highlight the currently-selected menu item in `IntegrationChoice` for
+ * every loaded source. Coercing both sides to Number fixes the comparison
+ * without changing behavior for code paths that already pass numbers.
+ *
+ * Empty/blank values never match — callers should treat them as "no selection"
+ * rather than "selection matching nothing".
+ */
+export function matchesIntegrationIdValue(integrationId: IntegrationType['id'], value: IntegrationIdValue): boolean {
+ if (value === undefined || value === null || value === '') {
+ return false
+ }
+ const target = Number(value)
+ if (!Number.isFinite(target)) {
+ return false
+ }
+ return Number(integrationId) === target
+}
+
+/**
+ * Lookup helper built on top of `matchesIntegrationIdValue`. Returns the
+ * integration matching the form value, or `undefined` if the list isn't loaded
+ * or the value doesn't correspond to any integration.
+ */
+export function findIntegrationByFormValue(
+ integrations: IntegrationType[] | null | undefined,
+ value: IntegrationIdValue
+): IntegrationType | undefined {
+ if (!integrations) {
+ return undefined
+ }
+ return integrations.find((integration) => matchesIntegrationIdValue(integration.id, value))
+}