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(convex): stop retrying schema discovery on a plan-gated 400 (#82252)

Tom Owerse1d56fe445b6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py
index 271dee1791d6..f0fa8b38aa0f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/convex.py
@@ -130,12 +130,30 @@ def _convex_get(url: str, deploy_key: str, params: dict[str, Any], timeout: int)
)
+class StreamingExportNotEnabledError(Exception):
+ """Raised when the Convex deployment's plan doesn't include streaming export access."""
+
+ pass
+
+
def get_json_schemas(deploy_url: str, deploy_key: str) -> dict[str, Any]:
url = f"{deploy_url.rstrip('/')}/api/json_schemas"
# byComponent=true groups the response by component so non-default components are discoverable.
response = _convex_get(
url, deploy_key, {"deltaSchema": "true", "format": "json", "byComponent": "true"}, timeout=30
)
+ if response.status_code == 400:
+ try:
+ error_data = response.json()
+ except ValueError:
+ error_data = {}
+ # A plain HTTPError's message never carries the response body, so without this the
+ # StreamingExportNotEnabled entry in get_non_retryable_errors can never match here -
+ # it only matched by accident via validate_credentials' own body parsing below.
+ if error_data.get("code") == "StreamingExportNotEnabled":
+ raise StreamingExportNotEnabledError(
+ "StreamingExportNotEnabled: streaming export requires the Convex Professional plan."
+ )
response.raise_for_status()
return response.json()
@@ -315,17 +333,13 @@ def validate_credentials(deploy_url: str, deploy_key: str) -> tuple[bool, str |
try:
get_json_schemas(clean_url, deploy_key)
return True, None
+ except StreamingExportNotEnabledError:
+ return (
+ False,
+ "Streaming export requires the Convex Professional plan. See https://www.convex.dev/plans to upgrade.",
+ )
except HTTPError as e:
if e.response is not None:
- try:
- error_data = e.response.json()
- if error_data.get("code") == "StreamingExportNotEnabled":
- return (
- False,
- "Streaming export requires the Convex Professional plan. See https://www.convex.dev/plans to upgrade.",
- )
- except Exception:
- pass
if e.response.status_code in (401, 403):
return False, "Invalid deploy key. Check your Convex deploy key and try again."
# Any other status falls through to a generic message. Keep the raw error
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py
index c6ed08213ae2..564ffeacbc9b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/convex/tests/test_convex.py
@@ -18,6 +18,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.convex.con
ConvexResumeConfig,
InvalidDeployUrlError,
InvalidWindowError,
+ StreamingExportNotEnabledError,
_convex_get,
convex_source,
document_deltas,
@@ -120,6 +121,17 @@ class TestValidateDeployUrl:
called_url = mock_get.return_value.get.call_args.args[0]
assert called_url.startswith("https://swift-lemur-123.convex.cloud/api/")
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")
+ def test_validate_credentials_surfaces_streaming_export_message(self, mock_get):
+ mock_get.return_value.get.return_value = _make_response({"code": "StreamingExportNotEnabled"}, status_code=400)
+
+ ok, err = validate_credentials("https://swift-lemur-123.convex.cloud", "prod:abc123")
+
+ assert not ok
+ assert err == (
+ "Streaming export requires the Convex Professional plan. See https://www.convex.dev/plans to upgrade."
+ )
+
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")
def test_validate_credentials_does_not_leak_url_on_http_error(self, mock_get):
err_response = Mock(status_code=400)
@@ -514,6 +526,34 @@ class TestConvexNonRetryableErrors:
non_retryable_errors = ConvexSource().get_non_retryable_errors()
assert any(key in error_msg for key in non_retryable_errors), error_msg
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")
+ def test_streaming_export_not_enabled_message_is_recognised_as_non_retryable(self, mock_get: Mock) -> None:
+ # get_schemas (schema discovery) calls get_json_schemas directly, unlike
+ # validate_credentials which already inspected the response body for this code. Without
+ # get_json_schemas surfacing the code itself, discovery only ever saw a bare HTTPError
+ # whose message never matches the "StreamingExportNotEnabled" non-retryable entry below.
+ mock_get.return_value.get.return_value = _make_response({"code": "StreamingExportNotEnabled"}, status_code=400)
+
+ with pytest.raises(StreamingExportNotEnabledError) as exc_info:
+ get_json_schemas("https://x.convex.cloud", "key")
+
+ error_msg = str(exc_info.value)
+ non_retryable_errors = ConvexSource().get_non_retryable_errors()
+ assert any(key in error_msg for key in non_retryable_errors), error_msg
+
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.convex.convex.make_tracked_session")
+ def test_get_json_schemas_400_with_unparseable_body_falls_through_to_http_error(self, mock_get: Mock) -> None:
+ # A 400 whose body isn't JSON (e.g. a proxy/edge error page) must not crash the
+ # body-parsing added for StreamingExportNotEnabled detection - it should fall through
+ # to the normal raise_for_status() error instead of raising an unhandled ValueError.
+ response = _make_response({}, status_code=400)
+ response.json.side_effect = ValueError("not JSON")
+ response.raise_for_status.side_effect = HTTPError(response=response)
+ mock_get.return_value.get.return_value = response
+
+ with pytest.raises(HTTPError):
+ get_json_schemas("https://x.convex.cloud", "key")
+
@parameterized.expand(
[
("401", "401 Client Error: Unauthorized for url: https://x.convex.cloud/api/document_deltas"),