Skip to content

Commit 710bc40

Browse files
authored
PYTHON-4870 - MongoClient.address should block until a connection suc… (mongodb#1929)
1 parent 872fda1 commit 710bc40

File tree

5 files changed

+2
-19
lines changed

5 files changed

+2
-19
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,13 +1453,6 @@ async def address(self) -> Optional[tuple[str, int]]:
14531453
'Cannot use "address" property when load balancing among'
14541454
' mongoses, use "nodes" instead.'
14551455
)
1456-
if topology_type not in (
1457-
TOPOLOGY_TYPE.ReplicaSetWithPrimary,
1458-
TOPOLOGY_TYPE.Single,
1459-
TOPOLOGY_TYPE.LoadBalanced,
1460-
TOPOLOGY_TYPE.Sharded,
1461-
):
1462-
return None
14631456
return await self._server_property("address")
14641457

14651458
@property

pymongo/synchronous/mongo_client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,13 +1447,6 @@ def address(self) -> Optional[tuple[str, int]]:
14471447
'Cannot use "address" property when load balancing among'
14481448
' mongoses, use "nodes" instead.'
14491449
)
1450-
if topology_type not in (
1451-
TOPOLOGY_TYPE.ReplicaSetWithPrimary,
1452-
TOPOLOGY_TYPE.Single,
1453-
TOPOLOGY_TYPE.LoadBalanced,
1454-
TOPOLOGY_TYPE.Sharded,
1455-
):
1456-
return None
14571450
return self._server_property("address")
14581451

14591452
@property

test/asynchronous/test_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,6 @@ async def test_init_disconnected(self):
838838
c = await self.async_rs_or_single_client(connect=False)
839839
self.assertIsInstance(c.topology_description, TopologyDescription)
840840
self.assertEqual(c.topology_description, c._topology._description)
841-
self.assertIsNone(await c.address) # PYTHON-2981
842-
await c.admin.command("ping") # connect
843841
if async_client_context.is_rs:
844842
# The primary's host and port are from the replica set config.
845843
self.assertIsNotNone(await c.address)

test/test_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,6 @@ def test_init_disconnected(self):
812812
c = self.rs_or_single_client(connect=False)
813813
self.assertIsInstance(c.topology_description, TopologyDescription)
814814
self.assertEqual(c.topology_description, c._topology._description)
815-
self.assertIsNone(c.address) # PYTHON-2981
816-
c.admin.command("ping") # connect
817815
if client_context.is_rs:
818816
# The primary's host and port are from the replica set config.
819817
self.assertIsNotNone(c.address)

test/test_replica_set_reconfig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def test_client(self):
5959

6060
with self.assertRaises(ServerSelectionTimeoutError):
6161
c.db.command("ping")
62-
self.assertEqual(c.address, None)
62+
with self.assertRaises(ServerSelectionTimeoutError):
63+
_ = c.address
6364

6465
# Client can still discover the primary node
6566
c.revive_host("a:1")

0 commit comments

Comments
 (0)