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-imports): stop the partition measurement clobbering sync_type_config (#94508)

Daniel RC9a35a79f73c3
diff --git a/products/warehouse_sources/backend/models/external_data_schema.py b/products/warehouse_sources/backend/models/external_data_schema.py
index d08e6fd3e9e5..e7d08f04eabb 100644
--- a/products/warehouse_sources/backend/models/external_data_schema.py
+++ b/products/warehouse_sources/backend/models/external_data_schema.py
@@ -714,8 +714,16 @@ class ExternalDataSchema(ModelActivityMixin, CreatedMetaFields, UpdatedMetaField
)
def record_partition_measurement(self, max_partition_bytes: int) -> None:
- self.sync_type_config["max_partition_bytes"] = max_partition_bytes
- self._save_sync_type_config()
+ # Deferred: this module loads during django.setup() and the util pulls in temporalio.
+ from posthog.temporal.common.utils import retry_on_db_connection_drop # noqa: PLC0415
+
+ self.sync_type_config = retry_on_db_connection_drop(
+ lambda: update_sync_type_config_keys(
+ self.id,
+ self.team_id,
+ updates={"max_partition_bytes": max_partition_bytes},
+ )
+ )
def set_repartition_pending(self, target: dict[str, Any]) -> None:
self.sync_type_config["repartition_pending"] = target
diff --git a/products/warehouse_sources/backend/tests/test_models.py b/products/warehouse_sources/backend/tests/test_models.py
index b154cd841724..66f0ed418121 100644
--- a/products/warehouse_sources/backend/tests/test_models.py
+++ b/products/warehouse_sources/backend/tests/test_models.py
@@ -322,6 +322,32 @@ class TestSaveSyncTypeConfigRetriesOnConnectionDrop(BaseTest):
schema.record_partition_measurement(123)
+class TestPartitionMeasurementPreservesConcurrentKeys(BaseTest):
+ def setUp(self) -> None:
+ super().setUp()
+ self.source = ExternalDataSource.objects.create(
+ team_id=self.team.pk,
+ source_id=str(uuid.uuid4()),
+ connection_id=str(uuid.uuid4()),
+ status="Completed",
+ source_type="Postgres",
+ )
+
+ def test_a_key_written_after_this_instance_loaded_survives(self) -> None:
+ schema = ExternalDataSchema.objects.create(
+ team_id=self.team.pk, source=self.source, name="users", sync_type_config={"incremental_field": "updated_at"}
+ )
+ stale = ExternalDataSchema.objects.get(id=schema.id)
+
+ update_sync_type_config_keys(schema.id, self.team.pk, updates={"last_full_run_at": "2026-09-03T12:00:00+00:00"})
+ stale.record_partition_measurement(4096)
+
+ schema.refresh_from_db()
+ assert schema.sync_type_config["last_full_run_at"] == "2026-09-03T12:00:00+00:00"
+ assert schema.sync_type_config["max_partition_bytes"] == 4096
+ assert schema.sync_type_config["incremental_field"] == "updated_at"
+
+
class TestExternalDataSchemaOOMEvent(BaseTest):
def _source(self, team_id: int | None = None) -> ExternalDataSource:
return ExternalDataSource.objects.create(