Skip to content

Commit a7c090d

Browse files
committed
add test for repr and change changelog
1 parent f33d091 commit a7c090d

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PyMongo 4.12 brings a number of changes including:
99
- Support for configuring DEK cache lifetime via the ``key_expiration_ms`` argument to
1010
:class:`~pymongo.encryption_options.AutoEncryptionOpts`.
1111
- Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
12+
- AsyncMongoClient no longer performs dns resolution for "mongodb+srv://" connection string in the constructor.
13+
To avoid blocking the asyncio loop, the resolution is now deferred until the client is first connected.
1214

1315
Issues Resolved
1416
...............

pymongo/asynchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ def option_repr(option: str, value: Any) -> str:
12551255

12561256
# Host first...
12571257
if self._topology is None:
1258-
options = self._resolve_srv_info["seeds"]
1258+
options = [f"host='mongodb+srv://{self._resolve_srv_info['fqdn']}'"]
12591259
else:
12601260
options = [
12611261
"host=%r"

pymongo/synchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def option_repr(option: str, value: Any) -> str:
12531253

12541254
# Host first...
12551255
if self._topology is None:
1256-
options = self._resolve_srv_info["seeds"]
1256+
options = [f"host='mongodb+srv://{self._resolve_srv_info['fqdn']}'"]
12571257
else:
12581258
options = [
12591259
"host=%r"

test/asynchronous/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,15 @@ async def test_repr(self):
933933
async with eval(the_repr) as client_two:
934934
self.assertEqual(client_two, client)
935935

936+
async def test_repr_srv_host(self):
937+
client = AsyncMongoClient("mongodb+srv://test1.test.build.10gen.cc/")
938+
# before srv resolution
939+
self.assertIn("host='mongodb+srv://test1.test.build.10gen.cc'", repr(client))
940+
await client.aconnect()
941+
# after srv resolution
942+
self.assertIn("host=['localhost.test.build.10gen.cc:", repr(client))
943+
await client.close()
944+
936945
async def test_getters(self):
937946
await async_wait_until(
938947
lambda: async_client_context.nodes == self.client.nodes, "find all nodes"

test/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,15 @@ def test_repr(self):
908908
with eval(the_repr) as client_two:
909909
self.assertEqual(client_two, client)
910910

911+
def test_repr_srv_host(self):
912+
client = MongoClient("mongodb+srv://test1.test.build.10gen.cc/")
913+
# before srv resolution
914+
self.assertIn("host='mongodb+srv://test1.test.build.10gen.cc'", repr(client))
915+
client._connect()
916+
# after srv resolution
917+
self.assertIn("host=['localhost.test.build.10gen.cc:", repr(client))
918+
client.close()
919+
911920
def test_getters(self):
912921
wait_until(lambda: client_context.nodes == self.client.nodes, "find all nodes")
913922

0 commit comments

Comments
 (0)