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): don't wipe webhook-first tables on re-enable (#70640)

Julian Bez7eb41636aae9
diff --git a/products/data_warehouse/backend/presentation/views/external_data_schema.py b/products/data_warehouse/backend/presentation/views/external_data_schema.py
index 49456ecc3188..1de0523c125e 100644
--- a/products/data_warehouse/backend/presentation/views/external_data_schema.py
+++ b/products/data_warehouse/backend/presentation/views/external_data_schema.py
@@ -876,7 +876,10 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):
if should_sync if should_sync is not None else instance.should_sync:
trigger_refresh = True
- # When re-enabling a webhook schema, force a full refresh to avoid missing data
+ # When re-enabling a webhook schema, request a pipeline reset so a gap from the
+ # off-window gets filled. Poll-backfillable sources honor it as a wipe plus full
+ # re-crawl; webhook-only sources (no poll backfill) resume webhook ingestion over
+ # the existing table instead of wiping it — see handle_reset_or_full_refresh.
if (
should_sync is True
and instance.should_sync is False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
index 7846092714f4..51b5fdf5172d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
@@ -263,10 +263,30 @@ async def handle_reset_or_full_refresh(
schema: "ExternalDataSchema",
delta_table_helper: DeltaTableHelper,
logger: FilteringBoundLogger,
+ webhook_only: bool = False,
) -> None:
- from products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchema
+ from products.warehouse_sources.backend.models.external_data_schema import (
+ ExternalDataSchema,
+ update_sync_type_config_keys,
+ )
- if reset_pipeline and not should_resume:
+ if reset_pipeline and webhook_only:
+ # A webhook-only table's rows exist only as webhook-delivered events — the poll does
+ # no backfill, so a wipe could never be rebuilt. Consume the reset request by resuming
+ # webhook ingestion over the existing table: buffered webhook files drain this run, and
+ # any events lost while ingestion was off are unrecoverable either way. Only the flag is
+ # cleared; the incremental watermark and initial_sync_complete are kept since nothing
+ # was wiped.
+ await logger.adebug("Skipping table reset for webhook-only schema; resuming webhook ingestion")
+ await database_sync_to_async_pool(update_sync_type_config_keys)(
+ schema.id, schema.team_id, removes=["reset_pipeline"]
+ )
+ # Also drop it from the in-memory config: a later watermark save (update_incremental_field_values
+ # / V3 staging) persists this same schema's sync_type_config, which would otherwise write
+ # reset_pipeline back and leave every subsequent run treated as a reset.
+ if schema.sync_type_config:
+ schema.sync_type_config.pop("reset_pipeline", None)
+ elif reset_pipeline and not should_resume:
await logger.adebug("Deleting existing table due to reset_pipeline being set")
await delta_table_helper.reset_table()
await database_sync_to_async_pool(schema.update_sync_type_config_for_reset_pipeline)()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
index f3a9d9300d11..2e1b9be74787 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
@@ -14,6 +14,7 @@ from products.warehouse_sources.backend.models.external_data_source import Exter
from products.warehouse_sources.backend.models.oom_event import ExternalDataSchemaOOMEvent
from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.extract import (
handle_corrupted_delta_log,
+ handle_reset_or_full_refresh,
report_heartbeat_timeout,
run_pre_write_defensive_compact,
)
@@ -222,3 +223,55 @@ class TestHandleCorruptedDeltaLog:
assert ph.capture.call_args.kwargs["event"] == "warehouse_delta_revived"
assert ph.capture.call_args.kwargs["properties"]["outcome"] == "salvaged"
assert ph.capture.call_args.kwargs["properties"]["made_non_billable"] is False
+
+
+# transaction=True: the webhook-first branch clears the reset flag via update_sync_type_config_keys,
+# which writes from the async thread pool and can't see an atomic TestCase's uncommitted rows.
[email protected]_db(transaction=True)
+class TestHandleResetOrFullRefresh:
+ def _webhook_schema(self, team) -> ExternalDataSchema:
+ source = ExternalDataSource.objects.create(
+ source_id=str(uuid.uuid4()), connection_id=str(uuid.uuid4()), team=team, source_type="Github"
+ )
+ return ExternalDataSchema.objects.create(
+ name="workflow_jobs",
+ team=team,
+ source=source,
+ sync_type=ExternalDataSchema.SyncType.WEBHOOK,
+ sync_type_config={"reset_pipeline": True, "incremental_field_last_value": "2026-01-01T00:00:00"},
+ initial_sync_complete=True,
+ )
+
+ def test_webhook_only_reset_preserves_table_and_state(self, team):
+ # The data-loss regression: a reset on a webhook-only schema must not wipe the Delta
+ # table (the poll can't rebuild webhook-accumulated rows). The reset request is consumed,
+ # while the watermark and initial_sync_complete survive so webhook ingestion resumes.
+ schema = self._webhook_schema(team)
+ helper = MagicMock(reset_table=AsyncMock())
+
+ async_to_sync(handle_reset_or_full_refresh)(
+ True, False, schema, helper, MagicMock(adebug=AsyncMock()), webhook_only=True
+ )
+
+ helper.reset_table.assert_not_awaited()
+ # In-memory config is cleared too — otherwise a later watermark save re-persists
+ # reset_pipeline and every subsequent run is treated as a reset.
+ assert "reset_pipeline" not in schema.sync_type_config
+ schema.refresh_from_db()
+ assert "reset_pipeline" not in schema.sync_type_config
+ assert schema.sync_type_config["incremental_field_last_value"] == "2026-01-01T00:00:00"
+ assert schema.initial_sync_complete is True
+
+ def test_poll_backfillable_reset_still_wipes(self, team):
+ # Guard against over-correction: a reset on a schema whose poll CAN rebuild the data
+ # must keep wiping so the re-crawl starts from a clean table.
+ schema = self._webhook_schema(team)
+ helper = MagicMock(reset_table=AsyncMock())
+
+ async_to_sync(handle_reset_or_full_refresh)(
+ True, False, schema, helper, MagicMock(adebug=AsyncMock()), webhook_only=False
+ )
+
+ helper.reset_table.assert_awaited_once()
+ schema.refresh_from_db()
+ assert "reset_pipeline" not in schema.sync_type_config
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py
index 3cdebad99c0c..8254b2bafdc7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/pipeline.py
@@ -243,7 +243,12 @@ class PipelineNonDLT(Generic[ResumableData]):
await handle_corrupted_delta_log(self._schema, self._job, self._delta_table_helper, self._logger)
await handle_reset_or_full_refresh(
- self._reset_pipeline, should_resume, self._schema, self._delta_table_helper, self._logger
+ self._reset_pipeline,
+ should_resume,
+ self._schema,
+ self._delta_table_helper,
+ self._logger,
+ webhook_only=self._resource.webhook_only,
)
# If the schema has no DWH table, it's a first ever sync
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/typings.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/typings.py
index bb21fc187781..0163b08fcb53 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/typings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/typings.py
@@ -61,6 +61,10 @@ class SourceResponse:
rows_to_sync: Optional[int] = None
has_duplicate_primary_keys: Optional[bool] = None
"""Whether incremental tables have non-unique primary keys"""
+ webhook_only: bool = False
+ """Webhook-fed resource whose poll path does no backfill: after a wipe the poll cannot
+ rebuild the table, so a requested pipeline reset preserves the Delta table and resumes
+ webhook ingestion instead."""
chunk_size: Optional[int] = None
"""Override the batcher's rows-per-chunk (defaults to DEFAULT_CHUNK_SIZE)."""
chunk_size_bytes: Optional[int] = None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
index 130a78782697..762764933782 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/pipeline.py
@@ -280,7 +280,12 @@ class PipelineV3(Generic[ResumableData]):
await handle_corrupted_delta_log(self._schema, self._job, self._delta_table_helper, self._logger)
await handle_reset_or_full_refresh(
- self._reset_pipeline, should_resume, self._schema, self._delta_table_helper, self._logger
+ self._reset_pipeline,
+ should_resume,
+ self._schema,
+ self._delta_table_helper,
+ self._logger,
+ webhook_only=self._resource.webhook_only,
)
is_fresh_sync = self._delta_table_helper.is_first_sync or self._schema.table is None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/attentive/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/attentive/source.py
index 6d4c137c75a6..0a4accc03598 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/attentive/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/attentive/source.py
@@ -240,7 +240,7 @@ class AttentiveSource(
def source_for_pipeline(self, config: AttentiveSourceConfig, inputs: SourceInputs) -> SourceResponse:
webhook_source_manager = self.get_webhook_source_manager(inputs)
- webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(True)
+ webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=True)
def items() -> Iterable[Any] | AsyncIterable[Any]:
if webhook_enabled:
@@ -257,4 +257,5 @@ class AttentiveSource(
partition_mode="datetime",
partition_format="week",
partition_keys=["created_at"],
+ webhook_only=True,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_webhook_s3.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_webhook_s3.py
index e297993116e7..68b5b75c298d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_webhook_s3.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/test/test_webhook_s3.py
@@ -133,11 +133,13 @@ class TestWebhookSourceManager:
@parameterized.expand(
[
- ("no_hog_function", False, True, True, False, False),
- ("not_webhook", True, False, True, False, False),
- ("initial_sync_not_complete", True, True, False, False, False),
- ("reset_pipeline_true", True, True, True, True, False),
- ("all_conditions_met", True, True, True, False, True),
+ ("no_hog_function", False, True, True, False, False, False),
+ ("not_webhook", True, False, True, False, False, False),
+ ("initial_sync_not_complete", True, True, False, False, False, False),
+ ("reset_pipeline_true", True, True, True, True, False, False),
+ ("all_conditions_met", True, True, True, False, False, True),
+ ("reset_pipeline_webhook_only", True, True, True, True, True, True),
+ ("initial_sync_incomplete_webhook_only", True, True, False, False, True, True),
]
)
async def test_webhook_enabled_conditions(
@@ -147,6 +149,7 @@ class TestWebhookSourceManager:
is_webhook,
initial_sync_complete,
reset_pipeline,
+ webhook_only,
expected,
):
manager = _make_manager(reset_pipeline=reset_pipeline)
@@ -168,7 +171,7 @@ class TestWebhookSourceManager:
"products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3.database_sync_to_async_pool",
side_effect=mock_db_sync_to_async,
):
- assert await manager.webhook_enabled() is expected
+ assert await manager.webhook_enabled(webhook_only) is expected
async def test_list_parquet_files_filters_correctly(self):
manager = _make_manager()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/webhook_s3.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/webhook_s3.py
index cb6a06e45861..974b5a3fa806 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/webhook_s3.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/webhook_s3.py
@@ -63,7 +63,7 @@ class WebhookSourceManager:
def _strip_s3_protocol(self, s3_path: str) -> str:
return s3_path.replace("s3://", "")
- async def webhook_enabled(self, skip_initial_sync_complete_check: bool = False) -> bool:
+ async def webhook_enabled(self, webhook_only: bool = False) -> bool:
from products.cdp.backend.models.hog_functions.hog_function import HogFunction
from products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchema
@@ -71,13 +71,18 @@ class WebhookSourceManager:
lambda: ExternalDataSchema.objects.get(id=self._inputs.schema_id, team_id=self._inputs.team_id)
)
+ # A webhook-first resource's poll does no backfill, so the poll can neither seed the
+ # table (skip the initial-sync gate) nor rebuild it after a reset (ignore reset_pipeline
+ # — honoring it would force the poll path and orphan rows only webhooks can provide).
if (
not schema.is_webhook
- or (skip_initial_sync_complete_check is not True and not schema.initial_sync_complete)
- or self._inputs.reset_pipeline
+ or (not webhook_only and not schema.initial_sync_complete)
+ or (not webhook_only and self._inputs.reset_pipeline)
):
await self._logger.adebug(
- f"webhook_enabled=False. schema.is_webhook={schema.is_webhook}. schema.initial_sync_complete={schema.initial_sync_complete}. self._inputs.reset_pipeline={self._inputs.reset_pipeline}"
+ f"webhook_enabled=False. schema.is_webhook={schema.is_webhook}. "
+ f"schema.initial_sync_complete={schema.initial_sync_complete}. "
+ f"webhook_only={webhook_only}. reset_pipeline={self._inputs.reset_pipeline}"
)
return False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/customer_io/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/customer_io/source.py
index aeff23afb93b..20633045e3bf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/customer_io/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/customer_io/source.py
@@ -276,7 +276,7 @@ class CustomerIOSource(
def _webhook_source_response(self, inputs: SourceInputs) -> SourceResponse:
webhook_source_manager = self.get_webhook_source_manager(inputs)
- webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(True)
+ webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=True)
def items() -> Iterable[Any] | AsyncIterable[Any]:
if webhook_enabled:
@@ -293,6 +293,7 @@ class CustomerIOSource(
partition_mode="datetime",
partition_format="week",
partition_keys=["timestamp"],
+ webhook_only=True,
)
def _api_source_response(self, config: CustomerIOSourceConfig, inputs: SourceInputs) -> SourceResponse:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
index ea1face026d7..f55737d7b40c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py
@@ -917,11 +917,12 @@ def github_source(
# i.e. workflow_jobs and reviews) would otherwise deadlock a fresh webhook schema: the
# zero-row poll never creates a table, so initial_sync_complete is never set, so
# webhook_enabled stays False forever and queued webhook files never drain. There
- # is no backfill to lose for these, so activate webhook mode from the first run
- # (skip the initial_sync_complete gate), the same way the Slack source does.
- skip_initial_sync_complete_check = endpoint_config.initial_lookback_days == 0
+ # is no backfill to lose for these, so activate webhook mode from the first run, the same
+ # way the Slack source does; being webhook-first also means a requested pipeline reset must
+ # not force the poll path or wipe the table (see handle_reset_or_full_refresh).
+ webhook_only = endpoint_config.initial_lookback_days == 0
webhook_enabled = (
- async_to_sync(webhook_source_manager.webhook_enabled)(skip_initial_sync_complete_check)
+ async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=webhook_only)
if webhook_source_manager is not None
else False
)
@@ -975,6 +976,7 @@ def github_source(
partition_mode="datetime" if endpoint_config.partition_key else None,
partition_format="week" if endpoint_config.partition_key else None,
partition_keys=[endpoint_config.partition_key] if endpoint_config.partition_key else None,
+ webhook_only=webhook_only,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/source.py
index 91d5d21c12cc..730f98deb6e9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/source.py
@@ -326,7 +326,7 @@ class RevenueCatSource(
def _webhook_source_response(self, inputs: SourceInputs) -> SourceResponse:
webhook_source_manager = self.get_webhook_source_manager(inputs)
- webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(True)
+ webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=True)
def items() -> Iterable[Any] | AsyncIterable[Any]:
if webhook_enabled:
@@ -347,6 +347,7 @@ class RevenueCatSource(
# the partition layer treats bare ints as seconds, so this gives
# us correctly-bucketed weekly partitions.
partition_keys=["created_at"],
+ webhook_only=True,
)
def _api_source_response(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slack/slack.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slack/slack.py
index 580dec20442a..00e794550e20 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slack/slack.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slack/slack.py
@@ -402,6 +402,7 @@ def slack_source(
) -> SourceResponse:
items: Callable[[], Iterable[Any] | AsyncIterable[Any]]
sort_mode: SortMode = "asc"
+ webhook_only = False
if endpoint == "$channels":
# Bypass rest_api_resource: Slack's conversations.list pagination is buggy when
@@ -433,16 +434,18 @@ def slack_source(
# `conversations.history` / `conversations.replies` backfill. That backfill makes one
# `conversations.replies` request per threaded message, which fans out into tens of
# thousands of rate-limited requests on workspaces with many channels and threads.
- # Passing `skip_initial_sync_complete_check=True` activates webhook mode from the very
- # first sync (the same pattern the Customer.io webhook tables use). Until the webhook is
- # configured and delivering events, the table stays empty rather than backfilling history.
+ # Passing `webhook_only=True` activates webhook mode from the very first sync and keeps
+ # a requested pipeline reset from wiping the table (the same pattern the Customer.io
+ # webhook tables use). Until the webhook is configured and delivering events, the table
+ # stays empty rather than backfilling history.
endpoint_config = messages_endpoint_config()
sort_mode = "desc"
+ webhook_only = True
if channel_id is None:
raise Exception(f"channel_not_found: {endpoint}")
- webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(True)
+ webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=True)
def channel_items() -> Iterable[Any] | AsyncIterable[Any]:
if webhook_enabled:
@@ -459,6 +462,7 @@ def slack_source(
partition_mode=endpoint_config.partition_mode,
partition_format=endpoint_config.partition_format,
sort_mode=sort_mode,
+ webhook_only=webhook_only,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/slack/test_slack.py b/products/warehouse_sources/backend/temporal/data_imports/sources/slack/test_slack.py
index c39f6f2ac069..195495df96bf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/slack/test_slack.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/slack/test_slack.py
@@ -502,7 +502,7 @@ class TestSlackSourceChannelMessagesWebhookOnly:
# Webhook mode is activated from the first sync (skip the initial-sync-complete gate).
# When disabled the table stays empty until webhook events arrive — never a historical backfill.
- manager.webhook_enabled.assert_awaited_once_with(True)
+ manager.webhook_enabled.assert_awaited_once_with(webhook_only=True)
assert items == expected_items
assert manager.get_items.called == expect_get_items_called
mock_backfill.assert_not_called()
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 13989e711f27..5d2d0e84be50 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
@@ -628,7 +628,11 @@ def stripe_source(
incremental_field_config = APPEND_ONLY_INCREMENTAL_FIELDS.get(endpoint, [])
incremental_field_name = incremental_field_config[0]["field"] if incremental_field_config else "created"
- webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)()
+ # Webhook-only endpoints (e.g. Discount) have no list endpoint to poll, so the webhook is the
+ # sole source of truth: activate webhook mode from the first sync and skip the reset wipe on
+ # re-enable — a poll could never rebuild the table.
+ webhook_only = endpoint in WEBHOOK_ONLY_ENDPOINTS
+ webhook_enabled = async_to_sync(webhook_source_manager.webhook_enabled)(webhook_only=webhook_only)
def items():
if webhook_enabled:
@@ -650,6 +654,7 @@ def stripe_source(
primary_keys=["id"],
name=endpoint,
column_hints=column_hints,
+ webhook_only=webhook_only,
# Stripe data is returned in descending timestamp order
sort_mode="desc",
partition_count=1, # this enables partitioning
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 0e2a95fa58d7..f4ef55cb5337 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
@@ -8,6 +8,7 @@ from unittest.mock import MagicMock, patch
import stripe as stripe_lib
from stripe import ListObject
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.webhook_s3 import WebhookSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import (
StripeAuthMethodConfig,
StripeSourceConfig,
@@ -17,6 +18,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.stripe.con
CUSTOMER_BALANCE_TRANSACTION_RESOURCE_NAME,
CUSTOMER_PAYMENT_METHOD_RESOURCE_NAME,
CUSTOMER_RESOURCE_NAME,
+ DISCOUNT_RESOURCE_NAME,
RESOURCE_TO_STRIPE_WEBHOOK_EVENT,
SUBSCRIPTION_RESOURCE_NAME,
)
@@ -540,6 +542,39 @@ class TestWebhookEventMapping:
assert any(e.startswith("payment_method.") for e in _all_known_webhook_events())
+class TestWebhookOnlyResponseWiring:
+ def _make_manager(self, enabled: bool) -> MagicMock:
+ manager = MagicMock(spec=WebhookSourceManager)
+ manager.webhook_enabled = mock.AsyncMock(return_value=enabled)
+ return manager
+
+ def _source(self, endpoint: str, manager: MagicMock) -> Any:
+ return stripe_module.stripe_source(
+ api_key="sk_test_123",
+ account_id=None,
+ endpoint=endpoint,
+ db_incremental_field_last_value=None,
+ db_incremental_field_earliest_value=None,
+ logger=MagicMock(adebug=mock.AsyncMock()),
+ resumable_source_manager=MagicMock(can_resume=MagicMock(return_value=False)),
+ webhook_source_manager=manager,
+ )
+
+ def test_discount_response_is_webhook_only(self) -> None:
+ # Discount has no list endpoint, so its SourceResponse must carry webhook_only=True —
+ # otherwise a re-enable reset wipes the table with no poll able to rebuild it (data loss).
+ manager = self._make_manager(enabled=False)
+ response = self._source(DISCOUNT_RESOURCE_NAME, manager)
+ assert response.webhook_only is True
+ manager.webhook_enabled.assert_awaited_once_with(webhook_only=True)
+
+ def test_pollable_response_is_not_webhook_only(self) -> None:
+ manager = self._make_manager(enabled=False)
+ response = self._source(CUSTOMER_RESOURCE_NAME, manager)
+ assert response.webhook_only is False
+ manager.webhook_enabled.assert_awaited_once_with(webhook_only=False)
+
+
class TestSchemaWebhookCapability:
def setup_method(self):
self.source = StripeSource()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/github/test_github_source.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/github/test_github_source.py
index 18c5d33bec7d..26969492517d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/github/test_github_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/github/test_github_source.py
@@ -579,7 +579,7 @@ class TestGithubWebhookActivationGate:
db_incremental_field_last_value=None,
webhook_source_manager=manager,
)
- manager.webhook_enabled.assert_called_once_with(expected_skip)
+ manager.webhook_enabled.assert_called_once_with(webhook_only=expected_skip)
def test_webhook_path_drains_manager_when_enabled(self) -> None:
# Gate skipped + webhook_enabled True: items() reads the webhook manager (S3