From 710bc40c730d2fd982e1cb7a41fd91ac7b5d4498 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 15 Oct 2024 12:12:18 -0400 Subject: [PATCH] =?UTF-8?q?PYTHON-4870=20-=20MongoClient.address=20should?= =?UTF-8?q?=20block=20until=20a=20connection=20suc=E2=80=A6=20(#1929)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pymongo/asynchronous/mongo_client.py | 7 ------- pymongo/synchronous/mongo_client.py | 7 ------- test/asynchronous/test_client.py | 2 -- test/test_client.py | 2 -- test/test_replica_set_reconfig.py | 3 ++- 5 files changed, 2 insertions(+), 19 deletions(-) diff --git a/pymongo/asynchronous/mongo_client.py b/pymongo/asynchronous/mongo_client.py index bfae302da..4e09efe40 100644 --- a/pymongo/asynchronous/mongo_client.py +++ b/pymongo/asynchronous/mongo_client.py @@ -1453,13 +1453,6 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]): 'Cannot use "address" property when load balancing among' ' mongoses, use "nodes" instead.' ) - if topology_type not in ( - TOPOLOGY_TYPE.ReplicaSetWithPrimary, - TOPOLOGY_TYPE.Single, - TOPOLOGY_TYPE.LoadBalanced, - TOPOLOGY_TYPE.Sharded, - ): - return None return await self._server_property("address") @property diff --git a/pymongo/synchronous/mongo_client.py b/pymongo/synchronous/mongo_client.py index 1351cb200..815446bb2 100644 --- a/pymongo/synchronous/mongo_client.py +++ b/pymongo/synchronous/mongo_client.py @@ -1447,13 +1447,6 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]): 'Cannot use "address" property when load balancing among' ' mongoses, use "nodes" instead.' ) - if topology_type not in ( - TOPOLOGY_TYPE.ReplicaSetWithPrimary, - TOPOLOGY_TYPE.Single, - TOPOLOGY_TYPE.LoadBalanced, - TOPOLOGY_TYPE.Sharded, - ): - return None return self._server_property("address") @property diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index c6b6416c1..590154b85 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -838,8 +838,6 @@ class TestClient(AsyncIntegrationTest): c = await self.async_rs_or_single_client(connect=False) self.assertIsInstance(c.topology_description, TopologyDescription) self.assertEqual(c.topology_description, c._topology._description) - self.assertIsNone(await c.address) # PYTHON-2981 - await c.admin.command("ping") # connect if async_client_context.is_rs: # The primary's host and port are from the replica set config. self.assertIsNotNone(await c.address) diff --git a/test/test_client.py b/test/test_client.py index 8e3d9c8b8..5bbb5bd75 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -812,8 +812,6 @@ class TestClient(IntegrationTest): c = self.rs_or_single_client(connect=False) self.assertIsInstance(c.topology_description, TopologyDescription) self.assertEqual(c.topology_description, c._topology._description) - self.assertIsNone(c.address) # PYTHON-2981 - c.admin.command("ping") # connect if client_context.is_rs: # The primary's host and port are from the replica set config. self.assertIsNotNone(c.address) diff --git a/test/test_replica_set_reconfig.py b/test/test_replica_set_reconfig.py index 1dae0aea8..4c23d71b6 100644 --- a/test/test_replica_set_reconfig.py +++ b/test/test_replica_set_reconfig.py @@ -59,7 +59,8 @@ class TestSecondaryBecomesStandalone(MockClientTest): with self.assertRaises(ServerSelectionTimeoutError): c.db.command("ping") - self.assertEqual(c.address, None) + with self.assertRaises(ServerSelectionTimeoutError): + _ = c.address # Client can still discover the primary node c.revive_host("a:1")