: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): stop the GitHub source form dead-ending without a connected account (#87886)
Tom Owersefdf9971b9b6
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsxindex 46f8d7437379..14c0796a16c8 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx@@ -4008,6 +4008,18 @@ export const getErrorsForFields = (// emptiness check or `required` would pass with zero selections.const fieldValue = valueObj[field.name]const valueMissing = Array.isArray(fieldValue) ? fieldValue.length === 0 : !fieldValue++ // An OAuth field with nothing selected can never produce a working source, but some+ // backend configs keep it `required=False` so stored configs on the other auth branch+ // (e.g. GitHub PAT sources) still parse. Enforce it here instead of letting the submit+ // through to a guaranteed credentials error.+ if (field.type === 'oauth' && valueMissing) {+ // Label verbatim: OAuth field labels lead with a brand name ("GitHub account"),+ // which lowercasing would mangle.+ errorsObj[field.name] = `Select or connect a ${field.label}`+ return+ }+if ('required' in field && field.required && valueMissing) {errorsObj[field.name] = Array.isArray(fieldValue)? `Please enter at least one of your ${field.label.toLowerCase()}`diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardValidation.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardValidation.test.tsindex c5edd32a88e4..9fbb90e80463 100644--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardValidation.test.ts+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardValidation.test.ts@@ -1,6 +1,6 @@import type { SourceFieldConfig } from '~/queries/schema/schema-general'-import { normalizeMultiValue } from '../../shared/components/forms/IntegrationAccountSelector'+import { findOauthBranch, normalizeMultiValue } from '../../shared/components/forms/IntegrationAccountSelector'import { getErrorsForFields } from './sourceWizardLogic'const REPOSITORIES_FIELD: SourceFieldConfig = {@@ -13,6 +13,45 @@ const REPOSITORIES_FIELD: SourceFieldConfig = {multiple: true,}+// Mirrors GitHub's auth select: the OAuth field is `required: false` so stored PAT configs keep+// parsing, which used to let an empty OAuth submit through to a guaranteed credentials error.+const AUTH_METHOD_FIELD: SourceFieldConfig = {+ type: 'select',+ name: 'auth_method',+ label: 'Authentication type',+ required: true,+ defaultValue: 'oauth',+ options: [+ {+ label: 'OAuth (GitHub App)',+ value: 'oauth',+ fields: [+ {+ type: 'oauth',+ name: 'github_integration_id',+ label: 'GitHub account',+ required: false,+ kind: 'github',+ },+ ],+ },+ {+ label: 'Personal access token',+ value: 'pat',+ fields: [+ {+ type: 'text',+ name: 'personal_access_token',+ label: 'Personal access token',+ required: false,+ placeholder: '',+ secret: true,+ },+ ],+ },+ ],+}+describe('source wizard multi-value fields', () => {describe('getErrorsForFields', () => {// An empty array is truthy, so without the explicit length check "Next" would proceed@@ -36,6 +75,30 @@ describe('source wizard multi-value fields', () => {})expect(errors.payload.repositories).toBeUndefined()})++ it.each([+ [{ selection: 'oauth' }, 'Select or connect a GitHub account'],+ [{ selection: 'oauth', github_integration_id: 42 }, undefined],+ [{ selection: 'pat', personal_access_token: 'token' }, undefined],+ ])('oauth field on the selected branch with payload %p yields error %p', (authMethod, expectedError) => {+ const errors = getErrorsForFields([AUTH_METHOD_FIELD], {+ prefix: '',+ payload: { auth_method: authMethod },+ })+ expect(errors.payload.auth_method?.github_integration_id).toEqual(expectedError)+ })+ })++ describe('findOauthBranch', () => {+ // A wrong branch lookup either disables the repositories picker for PAT users or skips+ // the connect prompt for OAuth users; both are user-blocking.+ it.each([+ ['github_integration_id', { selectField: 'auth_method', optionValue: 'oauth', defaultValue: 'oauth' }],+ ['personal_access_token', undefined],+ ['not_a_field', undefined],+ ])('locates %p as %p', (integrationField, expected) => {+ expect(findOauthBranch([AUTH_METHOD_FIELD, REPOSITORIES_FIELD], integrationField)).toEqual(expected)+ })})describe('normalizeMultiValue', () => {diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsxindex bb6694db970f..6d02892337c1 100644--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx@@ -2,18 +2,54 @@ import { useActions, useValues } from 'kea'import { FormContext } from 'kea-forms'import { useContext, useEffect, useMemo, useRef } from 'react'-import { LemonInput, LemonInputSelect, LemonTag, Link } from '@posthog/lemon-ui'+import { LemonInput, LemonInputSelect, LemonSkeleton, LemonTag, Link } from '@posthog/lemon-ui'import api from 'lib/api'import { integrationAccountsLogic } from 'lib/integrations/integrationAccountsLogic'import { integrationsLogic } from 'lib/integrations/integrationsLogic'+import { getIntegrationNameFromKind } from 'lib/integrations/utils'import { LemonField } from 'lib/lemon-ui/LemonField'import type { LemonInputSelectOption } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'+import type { SourceFieldConfig } from '~/queries/schema/schema-general'+import { InputSuggestion, InputWithSuggestionsDropdown } from './InputWithSuggestionsDropdown'+export interface OauthBranchLocation {+ /** Name of the select field one of whose options nests the OAuth integration field. */+ selectField: string+ /** The option value whose fields include the OAuth integration field. */+ optionValue: string+ /** The select's default selection, in effect before the user touches the field. */+ defaultValue?: string+}++/** Locate the auth-method select branch that carries `integrationField` (e.g. GitHub's+ * `github_integration_id` inside the `auth_method` select). Returns undefined when the OAuth+ * field is top-level, meaning OAuth is the only auth path. */+export function findOauthBranch(+ fields: SourceFieldConfig[],+ integrationField: string+): OauthBranchLocation | undefined {+ for (const field of fields) {+ if (field.type !== 'select') {+ continue+ }+ for (const option of field.options) {+ if (option.fields?.some((sub) => sub.type === 'oauth' && sub.name === integrationField)) {+ return {+ selectField: field.name,+ optionValue: option.value,+ defaultValue: field.defaultValue ?? undefined,+ }+ }+ }+ }+ return undefined+}+export interface IntegrationAccountSelectorProps {fieldName: stringfieldLabel: string@@ -31,6 +67,10 @@ export interface IntegrationAccountSelectorProps {/** Legacy single-value payload field that seeds the multi picker when it's still empty* (e.g. GitHub sources saved before multi-repo support store `repository`). */legacySingleField?: string+ /** Where the OAuth integration field sits when it's nested under an auth-method select.+ * Lets the picker tell "OAuth chosen but not connected" (prompt to connect) apart from+ * a non-OAuth branch like a PAT (free entry is legitimate there). */+ oauthBranch?: OauthBranchLocation}/** Coerce a form value into the multi picker's string[] shape: undefined/'' -> [],@@ -97,7 +137,32 @@ function IntegrationAccountSelectorInner({)}, [integrationId, integrations, integrationsLoading, props.integrationKind])+ const branchState = useFormFieldValue(formLogic, formKey, props.oauthBranch?.selectField) as+ | Record<string, unknown>+ | undefined+ const oauthBranchActive =+ !props.oauthBranch ||+ (branchState?.['selection'] ?? props.oauthBranch.defaultValue) === props.oauthBranch.optionValue+if (props.multiple) {+ if (oauthBranchActive && !integrationIsValid) {+ if (integrationsLoading) {+ return <LemonSkeleton className="h-10" />+ }+ // The OAuth branch is selected but no working integration backs it: free entry+ // would only defer the failure to schema discovery, so point at the connect+ // control instead.+ return (+ <MultiAccountFieldInner+ fieldName={props.fieldName}+ fieldLabel={props.fieldLabel}+ caption={props.caption}+ options={[]}+ disabled+ hint={`Connect a ${getIntegrationNameFromKind(props.integrationKind)} account above to choose ${props.fieldLabel.toLowerCase()}.`}+ />+ )+ }return (<MultiAccountField{...props}@@ -312,6 +377,8 @@ function MultiAccountFieldInner({loading,onInputChange,error,+ disabled,+ hint,}: {fieldName: stringfieldLabel: string@@ -321,6 +388,8 @@ function MultiAccountFieldInner({loading?: booleanonInputChange?: (value: string) => voiderror?: string+ disabled?: boolean+ hint?: string}): JSX.Element {return (<LemonField name={fieldName} label={fieldLabel} help={captionHelp(caption)}>@@ -341,7 +410,9 @@ function MultiAccountFieldInner({options={options}loading={loading}onInputChange={onInputChange}+ disabled={disabled}/>+ {hint && <p className="m-0 text-xs text-secondary">{hint}</p>}{error && <p className="m-0 text-xs text-warning">{error}</p>}{malformed.length > 0 && (<p className="m-0 text-xs text-warning">diff --git a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsxindex 9d66c6f964d2..cfc7742e5d60 100644--- a/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/SourceForm.tsx@@ -38,7 +38,7 @@ import { CDC_SOURCE_TYPES } from '../../cdc'import { isCustomSourceAiBuilderEnabled } from './customSourceManifest'import { CustomSourceManifestBuilder } from './CustomSourceManifestBuilder'import { customSourceManifestBuilderLogic } from './customSourceManifestBuilderLogic'-import { IntegrationAccountSelector } from './IntegrationAccountSelector'+import { IntegrationAccountSelector, findOauthBranch } from './IntegrationAccountSelector'import { SourceIntegrationChoice } from './IntegrationChoice'import { parseConnectionStringForSource } from './parsers'import { supportsDirectQuery } from './schemaGroupingUtils'@@ -368,6 +368,7 @@ export const sourceFieldToElement = (caption={field.caption}multiple={field.multiple}legacySingleField={legacySingleField}+ oauthBranch={findOauthBranch(sourceConfig.fields, field.integrationField)}/>)}