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(twenty): treat Twenty's internal TypeError responses as non-retryable (#130300)

Tom Owers6310c3c9ed11
diff --git a/products/warehouse_sources/sources/twenty/source.py b/products/warehouse_sources/sources/twenty/source.py
index 6d2a99a77c33..1e33a1805af4 100644
--- a/products/warehouse_sources/sources/twenty/source.py
+++ b/products/warehouse_sources/sources/twenty/source.py
@@ -51,6 +51,11 @@ class TwentySource(ResumableSource[TwentySourceConfig, TwentyResumeConfig]):
**auth_non_retryable_errors(service="Twenty"),
HOST_NOT_ALLOWED_ERROR: "The Twenty instance URL is not allowed. Please use a publicly reachable host.",
HTTP_NOT_ALLOWED_ERROR: "The Twenty instance URL must use HTTPS. Please update the instance URL to use https://.",
+ # Twenty's own backend throws this for an unhandled server-side bug while building the
+ # query (observed on `opportunities` with an incremental filter + sort); it is a bug in
+ # Twenty, not in the request we send, and it reproduces identically on every retry since
+ # the request is unchanged until the sync's watermark moves past it.
+ "code=TypeError": "Twenty's API returned an internal error (TypeError) while processing this request. This is a bug on Twenty's side — please report it to Twenty support, or try again later once it's fixed.",
}
def get_retryable_errors(self) -> set[str]:
diff --git a/products/warehouse_sources/sources/twenty/tests/test_twenty.py b/products/warehouse_sources/sources/twenty/tests/test_twenty.py
index 700df71af3f3..ec4d3d4e8a2a 100644
--- a/products/warehouse_sources/sources/twenty/tests/test_twenty.py
+++ b/products/warehouse_sources/sources/twenty/tests/test_twenty.py
@@ -10,6 +10,7 @@ from products.warehouse_sources.sources.sdk.testing import (
ScriptedResponse,
SourceDriver,
always,
+ error_message_matches,
scripted_network,
)
from products.warehouse_sources.sources.twenty import twenty as twenty_module
@@ -236,3 +237,12 @@ class TestPagination:
)
assert result.requests[0].param("order_by") == "updatedAt[AscNullsFirst]"
+
+ def test_api_type_error_is_non_retryable(self):
+ # Twenty's own backend can throw an unhandled TypeError while building the query (observed
+ # on `opportunities`); the request is unchanged on every retry, so this must stop the sync
+ # instead of retrying forever.
+ result = _run(always(ScriptedResponse(status=400, json={"code": "TypeError"})), endpoint="opportunities")
+
+ assert result.raised is not None
+ assert error_message_matches(str(result.raised), TwentySource().get_non_retryable_errors())