: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): keep the sync error through a billing limit (#91883)
Daniel RC8283130fdaae
diff --git a/products/data_warehouse/backend/logic/external_data_source/jobs.py b/products/data_warehouse/backend/logic/external_data_source/jobs.pyindex b39265714739..1c7f7ae74f80 100644--- a/products/data_warehouse/backend/logic/external_data_source/jobs.py+++ b/products/data_warehouse/backend/logic/external_data_source/jobs.py@@ -112,6 +112,13 @@ def update_external_job_status(# source broke (or a non-retryable error paused extraction) must not repaint the schema# healthy while syncing is stopped. Which markers halt a schema is the model's business# (cdc_halted) — this generic layer only honors the state.++ # The billing gate stops a run before extraction, so it learns nothing about the source.+ # Clearing the error on its way through would erase the last real failure and hide a broken+ # connection behind the billing status for as long as the limit holds. The status still+ # moves: billing is what blocks this schema now.+ billing_limited_run = schema_status == ExternalDataSchemaStatus.BILLING_LIMIT_REACHED+if schema.cdc_halted:logger.info("dwh_schema_status_update_skipped_cdc_halted",@@ -121,7 +128,8 @@ def update_external_job_status()else:schema.status = schema_status- schema.latest_error = error_to_persist+ if not billing_limited_run:+ schema.latest_error = error_to_persistschema.save(update_fields=["status", "latest_error", "updated_at"])# Every risky terminal write (any non-Completed terminal, plus the takeover-recoverydiff --git a/products/data_warehouse/backend/logic/external_data_source/test/test_jobs.py b/products/data_warehouse/backend/logic/external_data_source/test/test_jobs.pyindex 5c517d6aebfb..68f89f0c2ba9 100644--- a/products/data_warehouse/backend/logic/external_data_source/test/test_jobs.py+++ b/products/data_warehouse/backend/logic/external_data_source/test/test_jobs.py@@ -368,6 +368,35 @@ class TestUpdateExternalJobStatus:assert schema.status == ExternalDataSchemaStatus.FAILEDassert schema.latest_error == "The replication slot no longer exists on the source database."+ @pytest.mark.parametrize(+ "starting_status,starting_error",+ [+ (ExternalDataSchemaStatus.FAILED, "connection failed: server closed the connection unexpectedly"),+ (ExternalDataSchemaStatus.COMPLETED, None),+ ],+ )+ def test_billing_limit_moves_the_status_but_keeps_the_error(self, starting_status, starting_error):+ # The billing gate returns before extraction, so a billing-limited run must not erase the+ # connection error a real failure left behind.+ team, _source, schema, job = _create_org_team_source_schema_job()+ schema.status = starting_status+ schema.latest_error = starting_error+ schema.save()++ with patch("products.data_warehouse.backend.logic.external_data_source.jobs.emit_data_import_app_metrics"):+ updated = update_external_job_status(+ job_id=str(job.id),+ team_id=team.pk,+ status=ExternalDataJobStatus.BILLING_LIMIT_REACHED,+ logger=MagicMock(),+ latest_error=None,+ )++ assert updated.status == ExternalDataJobStatus.BILLING_LIMIT_REACHED+ schema.refresh_from_db()+ assert schema.status == ExternalDataSchemaStatus.BILLING_LIMIT_REACHED+ assert schema.latest_error == starting_error+def test_rejected_transition_does_not_overwrite_schema_status(self):team, _source, schema, job = _create_org_team_source_schema_job()