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(data-warehouse): stop the source wizard dead-ending on the webhook step (#77183)

posthog[bot]68a63e8b8321
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
index 132c4f53a26b..0b7ddba2921e 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/NewSourceScene.tsx
@@ -1,4 +1,5 @@
import { MakeLogicType, BindLogic, connect, kea, path, selectors, useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { IconCopy, IconQuestion } from '@posthog/icons'
@@ -225,8 +226,9 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
isSelfManagedSource,
source,
sourceConnectionDetails,
+ isWebhookFieldInputsSubmitting,
} = useValues(sourceWizardLogic)
- const { onBack, onSubmit, setInitialConnector, setSourceConnectionDetailsValue, updateSource } =
+ const { onBack, onSubmit, onClear, setInitialConnector, setSourceConnectionDetailsValue, updateSource } =
useActions(sourceWizardLogic)
const selectedAccessMethod = getEffectiveAccessMethod(
currentStep,
@@ -267,7 +269,7 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
const nextButton = (disabledReason?: string | false): JSX.Element => (
<LemonButton
- loading={isLoading || manualLinkIsLoading}
+ loading={isLoading || manualLinkIsLoading || isWebhookFieldInputsSubmitting}
disabledReason={
disabledReason || (!canGoNext && (nextButtonDisabledReason || 'Finish this step to continue'))
}
@@ -311,6 +313,7 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
onBack,
isLoading,
manualLinkIsLoading,
+ isWebhookFieldInputsSubmitting,
canGoNext,
nextButtonDisabledReason,
nextButtonText,
@@ -373,7 +376,7 @@ function InternalSourcesWizard(props: NewSourcesWizardProps): JSX.Element {
) : currentStep === 5 ? (
<ProgressStep />
) : (
- <div>Something went wrong...</div>
+ <UnknownWizardStepFallback currentStep={currentStep} onRestart={onClear} />
)}
{footer()}
@@ -612,7 +615,8 @@ function WebhookSetupStep({
}: {
sourceWizardLogicProps?: SourceWizardLogicProps
}): JSX.Element {
- const { webhookResult, webhookCreating, selectedConnector, databaseSchema } = useValues(sourceWizardLogic)
+ const { webhookResult, webhookCreating, selectedConnector, databaseSchema, isWebhookFieldInputsSubmitting } =
+ useValues(sourceWizardLogic)
const { createWebhook } = useActions(sourceWizardLogic)
const webhookTables = databaseSchema
@@ -626,6 +630,7 @@ function WebhookSetupStep({
webhookTables={webhookTables}
webhookResult={webhookResult}
webhookCreating={webhookCreating}
+ webhookFieldsSubmitting={isWebhookFieldInputsSubmitting}
onCreateWebhook={createWebhook}
formLogic={sourceWizardLogicProps ? sourceWizardLogic(sourceWizardLogicProps) : sourceWizardLogic}
formKey="webhookFieldInputs"
@@ -636,3 +641,22 @@ function WebhookSetupStep({
function ProgressStep(): JSX.Element {
return <SyncProgressStep />
}
+
+function UnknownWizardStepFallback({
+ currentStep,
+ onRestart,
+}: {
+ currentStep: number
+ onRestart: () => void
+}): JSX.Element {
+ useEffect(() => {
+ posthog.captureException(new Error(`Data warehouse source wizard reached an unexpected step: ${currentStep}`))
+ // oxlint-disable-next-line react-hooks/exhaustive-deps
+ }, [])
+
+ return (
+ <LemonBanner type="error" action={{ children: 'Start over', onClick: onRestart }}>
+ This source setup ran into an unexpected step. Start over to try again.
+ </LemonBanner>
+ )
+}
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index d99d36f5206f..554afae11316 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -3051,19 +3051,24 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
actions.setIsLoading(false)
},
onSubmit: () => {
- // Shared function that triggers different actions depending on the current step
- if (values.currentStep === 1) {
+ // Shared function that triggers different actions depending on the current step.
+ // Snapshot the step once: some branches below (e.g. step 4) dispatch actions that
+ // synchronously advance `currentStep`, and re-reading `values.currentStep` after that
+ // would let this same call fall through into the next step's branch too.
+ const step = values.currentStep
+
+ if (step === 1) {
return
}
- if (values.currentStep === 2 && values.selectedConnector?.name) {
+ if (step === 2 && values.selectedConnector?.name) {
actions.submitSourceConnectionDetails()
- } else if (values.currentStep === 2 && values.isManualLinkFormVisible) {
+ } else if (step === 2 && values.isManualLinkFormVisible) {
selfManagedSourceLogic.actions.submitTable()
posthog.capture('source created', { sourceType: 'Manual' })
}
- if (values.currentStep === 3 && values.selectedConnector?.name) {
+ if (step === 3 && values.selectedConnector?.name) {
if (values.isDirectQueryMode) {
actions.updateSource({
payload: {
@@ -3242,7 +3247,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
})
}
- if (values.currentStep === 4) {
+ if (step === 4) {
if (webhookResultHasNoPendingInputs(values.webhookResult)) {
actions.onNext()
} else {
@@ -3250,9 +3255,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
// (validates, then triggers submitWebhookFields)
actions.submitWebhookFieldInputs()
}
- }
-
- if (values.currentStep === 5) {
+ } else if (step === 5) {
if (props.onComplete) {
props.onComplete()
} else {
@@ -3364,7 +3367,12 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
}
}
- actions.onNext()
+ // Only advance from the webhook step — guards against a stray double submission
+ // (e.g. the form's own Save button plus the wizard's Next button) re-firing this and
+ // pushing `currentStep` past the last real step.
+ if (values.currentStep === 4) {
+ actions.onNext()
+ }
},
handleRedirect: async ({ source }) => {
// By default, we assume the source is a valid external data source
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
index cd1880cbec61..6a810296275f 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceWizardLogic.test.ts
@@ -46,6 +46,34 @@ describe('sourceWizardLogic', () => {
}
})
+ it('advances from the webhook step to the progress step without also completing the wizard', () => {
+ // Regression test: onSubmit used to read `values.currentStep` again after onNext()
+ // advanced it, so a single click on step 4 (webhook) fell through into the step-5
+ // completion branch in the same call, skipping the progress step entirely.
+ const postgresSource = {
+ name: 'Postgres',
+ iconPath: '',
+ caption: null,
+ fields: [],
+ } as SourceConfig
+ const onComplete = jest.fn()
+ const logic = sourceWizardLogic({ availableSources: { Postgres: postgresSource }, onComplete })
+ const unmount = logic.mount()
+
+ try {
+ logic.actions.selectConnector(postgresSource)
+ logic.actions.setStep(4)
+ logic.actions.setWebhookResult({ success: true, webhook_url: 'https://example.com/webhook' })
+
+ logic.actions.onSubmit()
+
+ expect(logic.values.currentStep).toEqual(5)
+ expect(onComplete).not.toHaveBeenCalled()
+ } finally {
+ unmount()
+ }
+ })
+
it('does not hydrate the same source URL again after the wizard has started', () => {
const postgresSource = {
name: 'Postgres',
diff --git a/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx b/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
index 82d59b54635d..5d1b51294985 100644
--- a/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
+++ b/products/data_warehouse/frontend/shared/components/InlineSourceSetup.tsx
@@ -35,21 +35,30 @@ export interface InlineSourceSetupProps {
autoConfigureTables?: boolean
}
+interface InternalInlineSourceSetupProps extends InlineSourceSetupProps {
+ currentView: InlineSourceSetupView
+ selectedSource: ExternalDataSourceType | null
+ onSourceSelect: (sourceId: ExternalDataSourceType) => void
+ onBack: () => void
+ onFormSuccess: () => void
+}
+
function InternalInlineSourceSetup({
- onComplete,
featured = false,
title,
subtitle = 'Choose a source to import data from',
showWizard = false,
autoConfigureTables = false,
-}: InlineSourceSetupProps): JSX.Element {
+ currentView,
+ selectedSource,
+ onSourceSelect,
+ onBack,
+ onFormSuccess,
+}: InternalInlineSourceSetupProps): JSX.Element {
const { connectors } = useValues(sourceWizardLogic)
- const { onClear } = useActions(sourceWizardLogic)
const { searchParams, location } = useValues(router)
const { replace } = useActions(router)
- const [currentView, setCurrentView] = useState<InlineSourceSetupView>('selection')
- const [selectedSource, setSelectedSource] = useState<ExternalDataSourceType | null>(null)
const [expanded, setExpanded] = useState(!featured)
const [searchQuery, setSearchQuery] = useState('')
@@ -67,8 +76,7 @@ function InternalInlineSourceSetup({
}
const match = availableConnectors.find((c) => c.name.toLowerCase() === String(kind).toLowerCase())
if (match) {
- setSelectedSource(match.name)
- setCurrentView('connecting')
+ onSourceSelect(match.name)
}
// Consume the param so a later remount (refresh, back-navigation, cancel) doesn't force the
// wizard back open after the connection has already been handled.
@@ -96,24 +104,6 @@ function InternalInlineSourceSetup({
const effectiveTitle = title ?? `Choose from ${availableConnectors.length} sources`
- const handleSourceSelect = (sourceId: ExternalDataSourceType): void => {
- setSelectedSource(sourceId)
- setCurrentView('connecting')
- }
-
- const handleFormSuccess = (): void => {
- setCurrentView('selection')
- setSelectedSource(null)
- onClear()
- onComplete?.()
- }
-
- const handleBack = (): void => {
- setCurrentView('selection')
- setSelectedSource(null)
- onClear()
- }
-
return (
<div className="space-y-6">
{/* Source Selection */}
@@ -147,7 +137,7 @@ function InternalInlineSourceSetup({
<div
key={source.id}
className="flex items-center gap-3 p-3 rounded-lg border border-border bg-bg-light cursor-pointer"
- onClick={() => handleSourceSelect(source.id)}
+ onClick={() => onSourceSelect(source.id)}
>
<SourceIcon type={source.id} size="small" disableTooltip />
<span className="font-medium text-sm">{source.label}</span>
@@ -182,13 +172,13 @@ function InternalInlineSourceSetup({
<LemonCard hoverEffect={false}>
<div className="space-y-4">
<div className="flex items-center justify-between mb-4">
- <LemonButton type="secondary" size="small" onClick={handleBack}>
+ <LemonButton type="secondary" size="small" onClick={onBack}>
← Back to sources
</LemonButton>
</div>
<NewSourcesWizard
hideBackButton
- onComplete={handleFormSuccess}
+ onComplete={onFormSuccess}
allowedSources={availableConnectors.map((c: SourceConfig) => c.name)}
initialSource={selectedSource}
autoConfigureTables={autoConfigureTables}
@@ -202,6 +192,32 @@ function InternalInlineSourceSetup({
export function InlineSourceSetup(props: InlineSourceSetupProps): JSX.Element {
const { availableSources, availableSourcesLoading } = useValues(availableSourcesLogic)
+ const { onClear } = useActions(sourceWizardLogic)
+
+ const [currentView, setCurrentView] = useState<InlineSourceSetupView>('selection')
+ const [selectedSource, setSelectedSource] = useState<ExternalDataSourceType | null>(null)
+
+ // Defined once here and bound as the logic's `onComplete` below, so the wizard's step-5
+ // completion listener always sees this same callback — never the logic's unbound default —
+ // regardless of which of this component's `BindLogic` mounts happens to be active at that
+ // moment (see `NewSourcesWizard`'s own nested `BindLogic`, which receives this same callback).
+ const handleFormSuccess = (): void => {
+ setCurrentView('selection')
+ setSelectedSource(null)
+ onClear()
+ props.onComplete?.()
+ }
+
+ const handleSourceSelect = (sourceId: ExternalDataSourceType): void => {
+ setSelectedSource(sourceId)
+ setCurrentView('connecting')
+ }
+
+ const handleBack = (): void => {
+ setCurrentView('selection')
+ setSelectedSource(null)
+ onClear()
+ }
if (availableSourcesLoading) {
return <LemonSkeleton />
@@ -212,8 +228,18 @@ export function InlineSourceSetup(props: InlineSourceSetupProps): JSX.Element {
}
return (
- <BindLogic logic={sourceWizardLogic} props={{ availableSources }}>
- <InternalInlineSourceSetup {...props} />
+ <BindLogic
+ logic={sourceWizardLogic}
+ props={{ availableSources, onComplete: handleFormSuccess, autoConfigureTables: props.autoConfigureTables }}
+ >
+ <InternalInlineSourceSetup
+ {...props}
+ currentView={currentView}
+ selectedSource={selectedSource}
+ onSourceSelect={handleSourceSelect}
+ onBack={handleBack}
+ onFormSuccess={handleFormSuccess}
+ />
</BindLogic>
)
}
diff --git a/products/data_warehouse/frontend/shared/components/forms/WebhookSetupForm.tsx b/products/data_warehouse/frontend/shared/components/forms/WebhookSetupForm.tsx
index e1e5a7ec470a..8036e4b8da26 100644
--- a/products/data_warehouse/frontend/shared/components/forms/WebhookSetupForm.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/WebhookSetupForm.tsx
@@ -32,6 +32,8 @@ interface WebhookSetupFormProps {
webhookTables?: { name: string; label?: string | null }[]
webhookResult?: WebhookCreateResult | null
webhookCreating: boolean
+ /** Whether the manual webhook fields form is currently submitting — guards the Save button against double-submission */
+ webhookFieldsSubmitting?: boolean
onCreateWebhook: () => void
/** kea-forms logic and formKey for the manual webhook field inputs form */
formLogic?: LogicWrapper | BuiltLogic<any>
@@ -48,6 +50,7 @@ export function WebhookSetupForm({
webhookTables,
webhookResult,
webhookCreating,
+ webhookFieldsSubmitting = false,
onCreateWebhook,
formLogic,
formKey,
@@ -153,7 +156,7 @@ export function WebhookSetupForm({
<Form logic={formLogic} formKey={formKey} enableFormOnSubmit>
<div className="space-y-3 ph-no-capture">
{pendingFields.map((field: SourceFieldConfig) => sourceFieldToElement(field, sourceConfig))}
- <LemonButton type="primary" htmlType="submit">
+ <LemonButton type="primary" htmlType="submit" loading={webhookFieldsSubmitting}>
Save
</LemonButton>
</div>
@@ -187,7 +190,7 @@ export function WebhookSetupForm({
<Form logic={formLogic} formKey={formKey} enableFormOnSubmit>
<div className="space-y-3 ph-no-capture">
{webhookFields.map((field: SourceFieldConfig) => sourceFieldToElement(field, sourceConfig))}
- <LemonButton type="primary" htmlType="submit">
+ <LemonButton type="primary" htmlType="submit" loading={webhookFieldsSubmitting}>
Save
</LemonButton>
</div>
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
index 9a6b1f6b1fee..dd35a96f4fed 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
@@ -462,7 +462,7 @@ If automatic creation failed due to a permissions error and you're using a restr
self, config: StripeSourceConfig, webhook_url: str, team_id: int, api_version: str | None = None
) -> WebhookCreationResult:
api_key = self._get_api_key(config, team_id)
- return create_webhook(api_key, config.stripe_account_id, webhook_url)
+ return create_webhook(api_key, config.stripe_account_id, webhook_url, auth_method=config.auth_method.selection)
def get_desired_webhook_events(
self, config: StripeSourceConfig, eligible_schema_names: list[str]
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
index 91a7fc35f08f..ea6afa6f329d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
@@ -1075,7 +1075,12 @@ def _is_stripe_account_access_error(error: Exception, error_str: str) -> bool:
)
-def create_webhook(api_key: str, stripe_account_id: str | None, webhook_url: str) -> WebhookCreationResult:
+def create_webhook(
+ api_key: str,
+ stripe_account_id: str | None,
+ webhook_url: str,
+ auth_method: Literal["api_key", "oauth"] = "api_key",
+) -> WebhookCreationResult:
logger = LOGGER.bind()
filtered_events = _all_known_webhook_events()
@@ -1130,6 +1135,11 @@ def create_webhook(api_key: str, stripe_account_id: str | None, webhook_url: str
)
if "permission" in error_str.lower() or "403" in error_str or "forbidden" in error_str.lower():
+ if auth_method == "oauth":
+ return WebhookCreationResult(
+ success=False,
+ error="Your Stripe integration doesn't have permission to create webhooks. Set up the webhook manually below, or reconnect your Stripe integration and grant webhook access.",
+ )
return WebhookCreationResult(
success=False,
error="Your Stripe API key doesn't have permission to create webhooks. Please add the 'Write' permission for 'Webhook endpoints' to your API key, or create the webhook manually.",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index 819657cbc411..39e4684657a2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -75,6 +75,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.stripe.str
_RateLimitRetryingRequestsClient,
_scrub_client_secrets,
check_endpoint_permissions,
+ create_webhook,
get_rows,
validate_credentials as validate_stripe_credentials,
)
@@ -1131,3 +1132,29 @@ class TestSchemaWebhookCapability:
for name, schema in self.by_name.items():
expected = name in RESOURCE_TO_STRIPE_WEBHOOK_EVENT or schema.webhook_only
assert schema.supports_webhooks is expected, name
+
+
+class TestCreateWebhookPermissionErrorCopy:
+ # Regression test: a permission-denied webhook creation used to always tell the user to add
+ # the "Write" permission to their API key, even when the source was connected via OAuth and
+ # has no API key to edit.
+ @parameterized.expand(
+ [
+ ("api_key", "add the 'Write' permission for 'Webhook endpoints' to your API key"),
+ ("oauth", "reconnect your Stripe integration"),
+ ]
+ )
+ def test_permission_error_message_matches_auth_method(self, auth_method, expected_phrase):
+ with patch.object(stripe_module, "StripeClient") as mock_client_cls:
+ mock_client = mock_client_cls.return_value
+ mock_client.webhook_endpoints.create.side_effect = stripe_lib.PermissionError("forbidden")
+
+ result = create_webhook(
+ api_key="sk_test_123",
+ stripe_account_id=None,
+ webhook_url="https://example.com/webhook",
+ auth_method=auth_method,
+ )
+
+ assert result.success is False
+ assert expected_phrase in (result.error or "")