: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-imports): treat a missing job on the first read as non-reportable (#115402)
Tom Owers7c90a170fd77
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.pyindex 4adf2d2c3ceb..a7989afb04e5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/import_data_sync.py@@ -421,7 +421,18 @@ async def _import_data_with_reporting(inputs: ImportDataActivityInputs, logger:async with Heartbeater(factor=30), ShutdownMonitor() as shutdown_monitor:await setup_row_tracking(inputs.team_id, inputs.schema_id)- model = await _get_external_data_job(inputs.run_id)+ try:+ model = await _get_external_data_job(inputs.run_id)+ except ExternalDataJob.DoesNotExist as e:+ # The same condition check_billing_limits_activity, repartition_table.py and+ # calculate_table_size.py already treat as benign: this run_id can point at a job+ # that was never created, e.g. external_data_job.py's legacy-tuple safety net+ # handing through an older worker's create_external_data_job_model_activity result+ # during a rolling deploy. NonReportableError keeps a deploy skew out of error+ # tracking; Temporal retries the activity, and the next scheduled run recreates the+ # job if these retries don't land on a consistent worker.+ await logger.awarning(str(e))+ raise NonReportableError(f"Job {inputs.run_id} does not exist") from eif model.pipeline_version != ExternalDataJob.PipelineVersion.V3:# Only a job created before every run moved to V3 can get here, and the V2 pipelinediff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.pyindex 42705ba003a9..129a6ccf6cb2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_import_data_sync.py@@ -300,6 +300,28 @@ async def test_schema_deleted_mid_sync_routes_through_handler():source.parse_config.assert_not_called()+async def test_job_not_found_on_first_read_is_non_reportable():+ # A run_id can point at a job that was never created, e.g. an older worker's+ # create_external_data_job_model_activity still returning the legacy tuple result during a+ # rolling deploy (see external_data_job.py). Every other activity that fetches ExternalDataJob+ # by id already treats this as benign (check_billing_limits_activity, repartition_table.py,+ # calculate_table_size.py); this first read in the import activity must too, rather than+ # escaping raw and minting an error-tracking issue for a deploy skew.+ error = ExternalDataJob.DoesNotExist("ExternalDataJob matching query does not exist.")+ source = mock.MagicMock(spec=SimpleSource)++ with (+ _patched_activity(source),+ mock.patch.object(module, "_get_external_data_job", new=mock.AsyncMock(side_effect=error)),+ ):+ with pytest.raises(NonReportableError) as exc_info:+ await import_data_activity_sync(_inputs())++ assert exc_info.value.__cause__ is error+ source.parse_config.assert_not_called()++@parameterized.expand([("pooler_cooldown", OperationalError, "server login has been failing, cached error: (server_login_retry)"),