: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): stop surfacing a cancelled run as a bare "Cancelled" error (#83685)
Tom Owersd7da3509ebc9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.pyindex 42bbc360bb2e..14567f3337ae 100644--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py@@ -163,6 +163,11 @@ Any_Source_Errors: dict[str, str | None] = {UNEXPECTED_ERROR_MESSAGE = "An unexpected error has occurred"+CANCELLED_RUN_MESSAGE = (+ "This sync run was cancelled before it finished. This usually happens when a newer run replaces "+ "it or the source is paused. It will run again on its next schedule."+)+def _customer_facing_error(cause: BaseException | None) -> str:"""`latest_error` text a customer reads, without the leaked internal exception class name.@@ -179,6 +184,11 @@ def _customer_facing_error(cause: BaseException | None) -> str:# A wrapped ActivityError can carry no cause; `str(None)` would show the customer "None".if cause is None:return UNEXPECTED_ERROR_MESSAGE+ # A cancelled activity surfaces as a Temporal `CancelledError` whose `message` is the bare word+ # "Cancelled" — meaningless to a customer, and not a failure they caused (a newer run superseded+ # this one, the source was paused, or a worker was rolled). Give them something readable.+ if isinstance(cause, exceptions.CancelledError):+ return CANCELLED_RUN_MESSAGEmessage = getattr(cause, "message", None)return message or str(cause)diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.pyindex 9e9043a323b3..01e4f03ce64d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py@@ -6,7 +6,7 @@ from unittest import mockfrom django.test import SimpleTestCasefrom parameterized import parameterized-from temporalio.exceptions import ApplicationError+from temporalio.exceptions import ApplicationError, CancelledErrorfrom temporalio.testing import ActivityEnvironmentfrom posthog.temporal.utils import ExternalDataWorkflowInputs@@ -15,6 +15,7 @@ from products.warehouse_sources.backend.models.external_data_job import Externalfrom products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchemafrom products.warehouse_sources.backend.models.external_data_source import ExternalDataSourcefrom products.warehouse_sources.backend.temporal.data_imports.external_data_job import (+ CANCELLED_RUN_MESSAGE,UNEXPECTED_ERROR_MESSAGE,UpdateExternalDataJobStatusInputs,_customer_facing_error,@@ -39,6 +40,13 @@ class TestCustomerFacingError(SimpleTestCase):def test_falls_back_to_str_when_cause_has_no_message(self) -> None:assert _customer_facing_error(ValueError("connection reset")) == "connection reset"+ def test_cancelled_run_does_not_surface_the_bare_cancelled_word(self) -> None:+ # A superseded/paused run cancels the activity; its cause is a CancelledError whose message+ # is the bare word "Cancelled". The customer must get a readable message instead.+ result = _customer_facing_error(CancelledError())+ assert result == CANCELLED_RUN_MESSAGE+ assert result != "Cancelled"+def test_missing_cause_does_not_show_the_customer_none(self) -> None:assert _customer_facing_error(None) == UNEXPECTED_ERROR_MESSAGE