: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-warehouse): allow no_cursor_timeout fallback for MongoDB views (#76367)
posthog[bot]9e0009141f42
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/mongo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/mongo.pyindex 866500b6b13a..e796f0423edd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/mongo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/mongo.py@@ -562,9 +562,13 @@ def _get_rows_to_sync(collection: Collection, query: dict[str, Any], logger: Fil# Some Atlas tiers (e.g. free/shared) reject no_cursor_timeout outright with OperationFailure-# code 8000 ("noTimeout cursors are disallowed in this atlas tier"). Matched as a substring since-# the full error also carries the volatile clusterTime/signature payload.+# code 8000 ("noTimeout cursors are disallowed in this atlas tier"). A collection that's actually+# a view hits the same limitation from a different angle: MongoDB rewrites a find() against a+# view into an aggregate(), and noCursorTimeout isn't a valid aggregation option, so the read+# fails immediately with "Option noCursorTimeout not supported in aggregation" instead. Both are+# matched as substrings since the full errors also carry volatile clusterTime/signature payloads._NO_TIMEOUT_CURSORS_DISALLOWED = "noTimeout cursors are disallowed"+_NO_TIMEOUT_NOT_SUPPORTED_IN_AGGREGATION = "noCursorTimeout not supported in aggregation"def mongo_source(@@ -636,7 +640,11 @@ def mongo_source(except StopIteration:passexcept OperationFailure as e:- if _NO_TIMEOUT_CURSORS_DISALLOWED not in str(e):+ error_message = str(e)+ if (+ _NO_TIMEOUT_CURSORS_DISALLOWED not in error_message+ and _NO_TIMEOUT_NOT_SUPPORTED_IN_AGGREGATION not in error_message+ ):raise# Fails on the very first read before any document is yielded, so it's safe to# retry without no_cursor_timeout — the tradeoff is the CursorNotFound risk thatdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.pyindex 7aec50e76880..18ccfed514b9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_mongo.py@@ -670,14 +670,27 @@ class TestMongoSourceCursorLifecycle(SimpleTestCase):assert collection.last_cursor is not Noneassert collection.last_cursor.closed is True- def test_falls_back_to_normal_cursor_when_tier_disallows_no_timeout(self):+ @parameterized.expand(+ [+ (+ "atlas_tier_disallows_no_timeout",+ "noTimeout cursors are disallowed in this atlas tier, full error: {'ok': 0, 'errmsg': "+ "'noTimeout cursors are disallowed in this atlas tier', 'code': 8000, 'codeName': 'AtlasError'}",+ ),+ (+ "view_rejects_no_timeout_via_aggregation",+ "Option noCursorTimeout not supported in aggregation, full error: {'ok': 0, 'errmsg': "+ "'Option noCursorTimeout not supported in aggregation', 'code': 9, 'codeName': 'FailedToParse'}",+ ),+ ]+ )+ def test_falls_back_to_normal_cursor_when_no_timeout_is_rejected(self, _name: str, error_message: str):# Regression: some Atlas tiers (free/shared) reject no_cursor_timeout=True outright with- # OperationFailure code 8000, which previously failed the sync permanently. This fires on- # the very first read, so the fallback cursor must run instead and yield the real rows.- notimeout_error = OperationFailure(- "noTimeout cursors are disallowed in this atlas tier, full error: {'ok': 0, 'errmsg': "- "'noTimeout cursors are disallowed in this atlas tier', 'code': 8000, 'codeName': 'AtlasError'}"- )+ # OperationFailure code 8000, and MongoDB rewrites find() against a view into an+ # aggregate() where noCursorTimeout isn't a valid option — both fail permanently without+ # this fallback. Both fire on the very first read, so the fallback cursor must run instead+ # and yield the real rows.+ notimeout_error = OperationFailure(error_message)collection = _FakeCollection([], error=notimeout_error, fallback_docs=[{"_id": "1"}, {"_id": "2"}])rows = self._run_get_rows(collection)