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): keep incremental cursor config when switching to webhook sync (#68704)

estefania4dec617ed28b
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 d478774089e9..01e10002bd0d 100644
--- a/products/data_warehouse/backend/presentation/views/external_data_schema.py
+++ b/products/data_warehouse/backend/presentation/views/external_data_schema.py
@@ -722,9 +722,16 @@ class ExternalDataSchemaSerializer(serializers.ModelSerializer):
or payload.get("incremental_field_last_value") is None
)
- if "incremental_field" in data:
+ # Webhook schemas derive their incremental field from the source, so a null here is the
+ # client's "not applicable", not an intentional clear. Writing it would wipe the cursor
+ # config a previous append/incremental sync built up, turning the webhook initial sync
+ # into an unbounded full-history scan with no durable watermark progress.
+ is_webhook_target = resulting_sync_type == ExternalDataSchema.SyncType.WEBHOOK
+ if "incremental_field" in data and not (is_webhook_target and incremental_field is None):
payload["incremental_field"] = incremental_field
- if "incremental_field_type" in data:
+ if "incremental_field_type" in data and not (
+ is_webhook_target and data.get("incremental_field_type") is None
+ ):
payload["incremental_field_type"] = data.get("incremental_field_type")
# Lookback only applies to incremental — merge-by-PK makes re-reading the overlap window
diff --git a/products/data_warehouse/backend/tests/api/test_external_data_schema.py b/products/data_warehouse/backend/tests/api/test_external_data_schema.py
index d945b1886d2a..55382659e7bf 100644
--- a/products/data_warehouse/backend/tests/api/test_external_data_schema.py
+++ b/products/data_warehouse/backend/tests/api/test_external_data_schema.py
@@ -1414,6 +1414,7 @@ class TestExternalDataSchema(APIBaseTest):
"incremental_field": "created",
"incremental_field_type": "integer",
"incremental_field_last_value": 1000,
+ "incremental_field_earliest_value": 500,
},
table=table,
)
@@ -1437,9 +1438,12 @@ class TestExternalDataSchema(APIBaseTest):
return_value=mock_hog_fn_result,
),
):
+ # The frontend sends null incremental fields alongside the switch — they must not
+ # wipe the cursor config, or the webhook initial sync degrades to an unbounded
+ # full-history scan with no durable watermark progress.
response = self.client.patch(
f"/api/environments/{self.team.pk}/external_data_schemas/{schema.id}",
- data={"sync_type": "webhook"},
+ data={"sync_type": "webhook", "incremental_field": None, "incremental_field_type": None},
)
assert response.status_code == 200
@@ -1452,6 +1456,7 @@ class TestExternalDataSchema(APIBaseTest):
assert schema.sync_type_config.get("incremental_field") == "created"
assert schema.sync_type_config.get("incremental_field_type") == "integer"
assert schema.sync_type_config.get("incremental_field_last_value") == 1000
+ assert schema.sync_type_config.get("incremental_field_earliest_value") == 500
def test_update_schema_change_sync_type_incremental_field(self):
source = ExternalDataSource.objects.create(