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(exports): classify query ValidationError as a user export failure (#64943)

posthog[bot]ab71990fc19d
diff --git a/products/exports/backend/tasks/failure_handler.py b/products/exports/backend/tasks/failure_handler.py
index 8b4bd130be4e..b558cd4d8ff1 100644
--- a/products/exports/backend/tasks/failure_handler.py
+++ b/products/exports/backend/tasks/failure_handler.py
@@ -5,6 +5,7 @@ from django.db import OperationalError
from billiard.exceptions import SoftTimeLimitExceeded
from clickhouse_driver.errors import SocketTimeoutError
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
+from rest_framework.exceptions import ValidationError
from urllib3.exceptions import MaxRetryError, ProtocolError, ReadTimeoutError
from posthog.hogql.errors import (
@@ -100,6 +101,7 @@ EXCEPTIONS_TO_RETRY = (
USER_QUERY_ERRORS = (
QueryError,
HogQLSyntaxError,
+ ValidationError, # DRF validation of the user's query (e.g. a funnel with fewer than two steps)
ClickHouseQueryMemoryLimitExceeded, # Users should reduce the date range on their query (or materialise)
ClickHouseQueryTimeOut, # Users should switch to materialised queries if they run into this
CHQueryErrorIllegalTypeOfArgument,
@@ -137,8 +139,21 @@ TIMEOUT_ERROR_NAMES = frozenset(cls.__name__ for cls in TIMEOUT_ERRORS) | {"Time
def classify_failure_type(exception: Exception | str) -> str:
- exception_type = type(exception).__name__ if isinstance(exception, Exception) else exception
+ # Live exceptions are classified by actual type, not name: the name sets are derived from
+ # these same tuples, so isinstance has identical coverage while avoiding false positives from
+ # unrelated classes that merely share a name (django/pydantic ValidationError, builtin SyntaxError).
+ if isinstance(exception, Exception):
+ if isinstance(exception, TIMEOUT_ERRORS):
+ return FAILURE_TYPE_TIMEOUT_GENERATION
+ if isinstance(exception, USER_QUERY_ERRORS):
+ return FAILURE_TYPE_USER
+ if isinstance(exception, EXCEPTIONS_TO_RETRY):
+ return FAILURE_TYPE_SYSTEM
+ return FAILURE_TYPE_UNKNOWN
+ # Stored exception-class names (historical rows, backfill) only carry the name, so fall back to
+ # name matching. This is best-effort and can't distinguish same-named classes from other packages.
+ exception_type = exception
if exception_type:
if exception_type in TIMEOUT_ERROR_NAMES:
return FAILURE_TYPE_TIMEOUT_GENERATION
diff --git a/products/exports/backend/tasks/test/test_failure_handler.py b/products/exports/backend/tasks/test/test_failure_handler.py
index 3b3855ed0c3e..8cd19525bcaf 100644
--- a/products/exports/backend/tasks/test/test_failure_handler.py
+++ b/products/exports/backend/tasks/test/test_failure_handler.py
@@ -1,6 +1,9 @@
from unittest import TestCase
+from django.core.exceptions import ValidationError as DjangoValidationError
+
from parameterized import parameterized
+from rest_framework.exceptions import ValidationError
from products.exports.backend.tasks.failure_handler import (
FAILURE_TYPE_SYSTEM,
@@ -30,6 +33,7 @@ class TestIsUserQueryErrorType(TestCase):
("CHQueryErrorUnknownTable", True),
("ExcelColumnLimitExceeded", True),
("InvalidExportContext", True),
+ ("ValidationError", True), # DRF validation of the user's query (e.g. one-step funnel export)
# Non-user errors - should return False
("TimeoutError", False),
("ValueError", False),
@@ -62,6 +66,7 @@ class TestClassifyFailureType(TestCase):
("CHQueryErrorUnknownTable", FAILURE_TYPE_USER),
("ExcelColumnLimitExceeded", FAILURE_TYPE_USER),
("InvalidExportContext", FAILURE_TYPE_USER),
+ ("ValidationError", FAILURE_TYPE_USER),
# System errors (from EXCEPTIONS_TO_RETRY)
("CHQueryErrorS3Error", FAILURE_TYPE_SYSTEM),
("CHQueryErrorTooManySimultaneousQueries", FAILURE_TYPE_SYSTEM),
@@ -76,3 +81,24 @@ class TestClassifyFailureType(TestCase):
)
def test_classify_failure_type(self, exception_type: str, expected: str) -> None:
assert classify_failure_type(exception_type) == expected
+
+ def test_drf_validation_error_instance_classifies_as_user(self) -> None:
+ # The funnel validation rules raise rest_framework.exceptions.ValidationError
+ # (e.g. a funnel with fewer than two steps); it must classify as a user error.
+ exception = ValidationError("Funnels require at least two steps.", code="funnels_require_at_least_two_steps")
+ assert classify_failure_type(exception) == FAILURE_TYPE_USER
+
+ @parameterized.expand(
+ [
+ # Unrelated classes that merely share a name with a user-query error must not be
+ # mislabelled when passed as a live instance — only the in-scope DRF/HogQL types count.
+ (DjangoValidationError("not a query error"),),
+ (SyntaxError("a Python syntax error, not HogQL's"),),
+ ]
+ )
+ def test_same_named_foreign_exception_instances_are_not_user_errors(self, exception: Exception) -> None:
+ assert classify_failure_type(exception) == FAILURE_TYPE_UNKNOWN
+
+ def test_name_string_classification_is_unchanged_for_backfill(self) -> None:
+ # Stored rows only carry the class name, so the string path stays purely name-based.
+ assert classify_failure_type("ValidationError") == FAILURE_TYPE_USER