: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(warehouse_sources): drop leaked exception class name from sync errors (#81135)
Tom Owers3b9a5946e354
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 692cb66ec45c..d6629135e13c 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@@ -156,6 +156,28 @@ Any_Source_Errors: dict[str, str | None] = {}+UNEXPECTED_ERROR_MESSAGE = "An unexpected error has occurred"+++def _customer_facing_error(cause: BaseException | None) -> str:+ """`latest_error` text a customer reads, without the leaked internal exception class name.++ Temporal renders a wrapped activity failure as ``<ExceptionClass>: <message>`` (see+ `ApplicationError.__str__`), so ``str(cause)`` prefixes the customer-facing error with an+ internal Python class name that means nothing to them: ``RESTClientRetryableError`` for a+ REST source that exhausted its retries on an HTTP 429/5xx, ``NonReportableError`` for a+ retryable connection drop, or a raw driver ``OperationalError``. The wrapped ``message``+ carries the same detail without that prefix. This only affects errors we don't rewrite via+ the non-retryable map below (retryable exhaustion and unclassified failures); ``internal_error``+ still records the full ``str(cause)`` for debugging.+ """+ # A wrapped ActivityError can carry no cause; `str(None)` would show the customer "None".+ if cause is None:+ return UNEXPECTED_ERROR_MESSAGE+ message = getattr(cause, "message", None)+ return message or str(cause)++@dataclasses.dataclassclass UpdateExternalDataJobStatusInputs:team_id: int@@ -844,12 +866,12 @@ class ExternalDataJobWorkflow(PostHogWorkflow):# Handle other activity errors normallyupdate_inputs.status = ExternalDataJob.Status.FAILEDupdate_inputs.internal_error = str(e.cause)- update_inputs.latest_error = str(e.cause)+ update_inputs.latest_error = _customer_facing_error(e.cause)raiseexcept Exception as e:# Catch allupdate_inputs.internal_error = str(e)- update_inputs.latest_error = "An unexpected error has ocurred"+ update_inputs.latest_error = UNEXPECTED_ERROR_MESSAGEupdate_inputs.status = ExternalDataJob.Status.FAILEDraisefinally: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 979f784a03f8..9e9043a323b3 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@@ -3,7 +3,10 @@ import asynciofrom posthog.test.base import BaseTestfrom unittest import mock+from django.test import SimpleTestCase+from parameterized import parameterized+from temporalio.exceptions import ApplicationErrorfrom temporalio.testing import ActivityEnvironmentfrom posthog.temporal.utils import ExternalDataWorkflowInputs@@ -12,12 +15,34 @@ 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 (+ UNEXPECTED_ERROR_MESSAGE,UpdateExternalDataJobStatusInputs,+ _customer_facing_error,trigger_schedule_buffer_one_activity,update_external_data_job_model,)+class TestCustomerFacingError(SimpleTestCase):+ @parameterized.expand(+ [+ # Temporal wraps a retryable REST exhaustion / connection drop as an ApplicationError+ # whose str() is "<ClassName>: <message>". The customer-facing latest_error must be the+ # message alone, not the internal class name.+ ("rest_retryable", "RESTClientRetryableError", "HTTP 429 for https://api.example.com/usage"),+ ("driver_drop", "OperationalError", "connection failed: server closed the connection unexpectedly"),+ ]+ )+ def test_strips_leaked_internal_exception_class_name(self, _name: str, exc_type: str, message: str) -> None:+ assert _customer_facing_error(ApplicationError(message, type=exc_type)) == message++ def test_falls_back_to_str_when_cause_has_no_message(self) -> None:+ assert _customer_facing_error(ValueError("connection reset")) == "connection reset"++ def test_missing_cause_does_not_show_the_customer_none(self) -> None:+ assert _customer_facing_error(None) == UNEXPECTED_ERROR_MESSAGE++class TestTriggerScheduleBufferOneActivity(BaseTest):@parameterized.expand([("billable", True), ("non_billable", False)])def test_worker_shutdown_retry_keeps_the_runs_billable_flag(self, _name: str, billable: bool):