PYTHON-4870 - MongoClient.address should block until a connection suc… (#1929)
This commit is contained in:
parent
872fda179e
commit
710bc40c73
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user