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(mongodb): stop showing raw dns text when a cluster's srv record is gone (#110678)

Tom Owers74e6c5eeeb74
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
index 3d7182f03e3c..643794c2c903 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
@@ -159,7 +159,6 @@ class MongoDBSource(ResumableSource[MongoDBSourceConfig, MongoResumeConfig], Val
def get_non_retryable_errors(self) -> dict[str, str | None]:
auth_failed_msg = _MONGO_AUTHENTICATION_FAILED_MESSAGE
return {
- "The DNS query name does not exist": None,
_SERVER_TOO_OLD_MARKER: _MONGO_SERVER_TOO_OLD_MESSAGE,
# pymongo raises InvalidURI("Username and password must be escaped according to RFC 3986,
# use urllib.parse.quote_plus") before any network call when the credentials in the
@@ -208,6 +207,9 @@ class MongoDBSource(ResumableSource[MongoDBSourceConfig, MongoResumeConfig], Val
# match the marker rather than the topology suffix, which a reachable-but-down cluster
# emits too. A name that does not resolve stays unresolved until the user fixes it.
**dict.fromkeys(_DNS_NAME_NOT_FOUND_MARKERS, _MONGO_HOST_UNRESOLVED_MESSAGE),
+ # The same answer for a mongodb+srv:// URI, whose SRV lookup fails before pymongo picks a
+ # server. The raw dnspython text echoes the cluster host, so it never reaches the customer.
+ _SRV_DNS_NAME_NOT_FOUND_MARKER: _MONGO_HOST_UNRESOLVED_MESSAGE,
# pymongo removes every server whose replica set name differs from the `replicaSet` the
# connection string asks for, which empties the topology and names the set rather than a
# host in the selection error. A cluster that is merely down keeps its servers as Unknown
diff --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.py
index c5a5cdae12c4..f49f8152dea5 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
@@ -553,6 +553,7 @@ class TestMongoDBNonRetryableErrors(SimpleTestCase):
("message", "Authentication failed", "password"),
("atlas_bad_auth", "bad auth", "password"),
("dns_name_not_found", "Name or service not known", "resolved"),
+ ("srv_dns_name_not_found", "The DNS query name does not exist", "resolved"),
("atlas_sql_endpoint", "query.mongodb.net", "connection string"),
("unescaped_credentials", "must be escaped according to RFC 3986", "connection string"),
("document_missing_id", "one of its documents has no _id field", "view"),